feat: add semantic error classes#38
Open
bjeanes wants to merge 3 commits intozammad:masterfrom
Open
Conversation
Note: these intentionally do not modify the specs here in order to ensure this change is as backwards-compatible as I am able to discover.
The errors_spec.rb also validates the interface (inheritance chain of errors and the derived `message`) to maximise the odds that any existing consumer which matches on the message of existing `RuntimeError`s will not experience a breaking change.
If the response is not 2xx in these cases, then the new error handling code will already re-parse the response body and throw these results away. Potentially, it makes sense here to remove `safe_json_parse` and return to prior behaviour of raising `JSON::ParserError` here, since that should now only happen on a 2xx which is indeed an _exceptional_ scenario. However, I am leaving it for now since this was recently released in a gem version, so could be considered a regression to change again. We'll see what the Zammad maintainers think...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, this is a follow-up to #29 and its speedy fix in c3af2a9.
While that fix removed the
JSON::ParserError, it led to a context-lessRuntimeErrorwithout sufficient information to programmatically discern error reasons. This affects our usage because we do things such as create tickets in background jobs and knowing when to retry (e.g. a 5xx error) vs give up and log an exception more visibly is important.This PR includes commits to introduce new semantic/contextful exceptions to the failure paths, taking care to:
RuntimeError, same#message, etc)This PR does not tackle reverting the recent introduction of
safe_json_parsebecause that could be considered a breaking change, though I am in favour of doing so because its remaining usages are only in the success paths, which could lead to a scenario where a 2xx response which somehow included corrupt JSON would not be detectable. In that case, aJSON::ParserErrordoes feel appropriate. Nonetheless, I'll leave the decision to include that change to the maintainers.This PR is best reviewed commit-by-commit. The first commit introduces the new error classes but preserves all existing specs in an effort to demonstrate backwards compatibility. The second commit changes the specs and introduces tests for the error classes themselves, to support ongoing regression prevention for existing code which may match on the contents of
RuntimeError#message.I hope this code can be merged quickly and I'm more than happy to make revisions as you see fit to get it to an acceptable state.