Skip to content

Add HotCell::Verdict so a raised exception carries its failure - #104

Merged
flavorjones merged 3 commits into
masterfrom
card-644-failure-on-raised-exception
Oct 7, 2026
Merged

flavorjones merged 3 commits into
masterfrom
card-644-failure-on-raised-exception

Conversation

@flavorjones

@flavorjones flavorjones commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Motivation

The client raises the application's registered permanent: or transient: class with failure.to_s as the message (client.rb#L203). An application that needs the failure's code or cause has to parse that message. HEY does this to show a lock placeholder for a password-protected PDF: it matches mutool's stderr inside the message (encryption_aware_pdf_previewer.rb#L27).

Fixes #97

Details

This is Donal's carry-the-failure branch, rebased onto master, with docs, a changelog entry, and the same change to the legacy client.

The client now extends each exception it raises for a failed call with a new HotCell::Verdict module. The module's hot_cell_failure reader returns the HotCell::Failure, so an application can rescue its own class and read the code and cause directly, such as the protected cause that #96 added:

rescue ActiveStorage::PreviewError => error
  raise unless error.hot_cell_failure.cause == HotCell::Codes::PROTECTED

Because Verdict is a module on the instance, an application can also rescue HotCell::Verdict to catch a failed call whatever classes it registered. The exception's class and message are unchanged.

docs/codes.md documents the module under "Exception classes", and docs/client-api.md links there.

hotcell-client-legacy (#102) now follows the same pattern. Its PermanentFailure and TransientFailure include a HotCell::Client::Legacy::Verdict module, and hot_cell_failure returns a HotCell::Client::Legacy::Failure with the same readers as HotCell::Failure. These replace the code reader and the raw error Hash. The gem is unreleased, so no application depends on the old readers.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The client raises the application's own classes with failure.to_s as
the message, so an application reading the code or cause had to parse
the message. Verdict.wrap now extends the exception with the failure
itself — and because Verdict is a module on the instance, an
application can also rescue HotCell::Verdict directly, whatever classes
its registration injected.
@flavorjones
flavorjones force-pushed the card-644-failure-on-raised-exception branch from e020783 to 87ef1a2 Compare October 7, 2026 21:28
Describe `hot_cell_failure` and `rescue HotCell::Verdict` under
"Exception classes" in `docs/codes.md`, and link there from
`docs/client-api.md`.

[Fix #97]
The legacy client exposed a failure as a `code` reader and a raw `error`
Hash, unlike `hotcell-client`'s `hot_cell_failure`. Replace both with
`hot_cell_failure`, which returns a `Failure` with the readers of
`HotCell::Failure`. Include a new `Verdict` module in both failure
classes, so `rescue Verdict` catches either.
@flavorjones
flavorjones force-pushed the card-644-failure-on-raised-exception branch from 87ef1a2 to 4fdba63 Compare October 7, 2026 21:34
@flavorjones
flavorjones requested a balanced review from Copilot October 7, 2026 21:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@flavorjones
flavorjones merged commit 207561e into master Oct 7, 2026
32 of 33 checks passed
@flavorjones
flavorjones deleted the card-644-failure-on-raised-exception branch October 7, 2026 21:40
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.

Expose the failure on the exception the client raises

3 participants