Skip to content

feat(common): add retriability signal to Result pattern Err type (#121)#168

Open
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:feat/result-retriable-signal
Open

feat(common): add retriability signal to Result pattern Err type (#121)#168
b3lz3but wants to merge 1 commit intocaptainpragmatic:masterfrom
b3lz3but:feat/result-retriable-signal

Conversation

@b3lz3but
Copy link
Copy Markdown
Contributor

@b3lz3but b3lz3but commented Apr 2, 2026

Summary

Adds a retriable: bool = False field to the Err dataclass so callers can distinguish transient errors (DB timeout, lock contention) from permanent ones (validation failure, business rule violation).

Closes #121

Change

# Before
@dataclass(frozen=True)
class Err[E]:
    error: E

# After
@dataclass(frozen=True)
class Err[E]:
    error: E
    retriable: bool = False

Backward compatibility

All 577 existing Err("message") call sites continue to work unchanged — the default retriable=False is applied automatically. No migration needed.

Usage

# Transient error — caller may retry
return Err("database connection timeout", retriable=True)

# Permanent error — retry will always fail (default)
return Err("invoice amount must be positive")

# Django-Q task can check:
result = refund_service.process_refund(order_id)
if result.is_err() and result.retriable:
    raise result.unwrap_err()  # Re-raise for Django-Q retry

Files changed

  • apps/common/types.py — Added retriable field to Err dataclass (+5 lines)
  • tests/common/test_result_types.py — 24 new tests covering Ok/Err behavior and retriable signal

Test plan

  • 24 Result type tests pass
  • All pre-commit hooks pass
  • DCO sign-off

🤖 Generated with Claude Code

…tainpragmatic#121)

Add retriable: bool = False field to the Err dataclass so callers (e.g.
Django-Q tasks) can distinguish transient errors (DB timeout, lock
contention) from permanent ones (validation failure). Default False
preserves backward compatibility with all 577 existing Err() call sites.

Closes captainpragmatic#121

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ciprian Radulescu <craps2003@gmail.com>
@b3lz3but
Copy link
Copy Markdown
Contributor Author

b3lz3but commented Apr 2, 2026

@mostlyvirtual — small arch-debt cleanup, requesting review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(common): add retriability signal to Result pattern Err type

1 participant