Skip to content

Conversation

@jakobw
Copy link
Contributor

@jakobw jakobw commented Oct 21, 2022

Hi again 👋

@Silvan-WMDE, @outdooracorn and I worked on the aforementioned improvements to JsonPatch errors. Here is what we did:

  • JsonPatch::import() now throws a MissingFieldException in case of a missing field. The exception contains the name of the missing field and the operation.
  • JsonPatch::import() now throws a UnknownOperationException in case of an unknown operation type. The exception contains the operation.
  • PatchTestOperationFailedException now contains the failed operation and the value that caused the test operation to fail.
  • JsonPatch::apply() now throws a PathException in case anything is wrong with the path in a "path" or "from" field of an operation. The exception contains the name of the problematic field ("path" or "from") and the operation.
  • JsonPointer now always throws JsonPointerException instead of a generic Exception.

This last point isn't really something we planned on doing, but it helped us in our implementation of the PathException case above. We also considered an alternative approach in https://github.com/wmde/json-diff/pull/4/files that didn't require the introduction of a JsonPointerException. We'd be curious to hear your thoughts on it, or alternative ideas!

The changes are fairly well split up into commits. Let me know if that works, or if you'd rather have the changes submitted individually or sliced differently.

Thanks! :)

Fixes #53.

outdooracorn and others added 5 commits October 21, 2022 11:26
- UnknownOperationException
- MissingFieldException

Co-authored-by: sihe <[email protected]>
This adds the failed operation and the actual value that failed the
test operation check to the exception.
Replace all occurences of the generic Exception in JsonPointer with the
more specific JsonPointerException so that the origin of the error is
made explicit and can be handled by consuming code.
This exception is thrown in JsonPatch::apply whenever a JsonPointer
call fails.
@codecov
Copy link

codecov bot commented Oct 21, 2022

Codecov Report

Merging #57 (478e618) into master (ccfc713) will increase coverage by 0.22%.
The diff coverage is 93.84%.

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   96.63%   96.85%   +0.22%     
==========================================
  Files          10       14       +4     
  Lines         535      573      +38     
==========================================
+ Hits          517      555      +38     
  Misses         18       18              
Impacted Files Coverage Δ
src/JsonPointer.php 94.89% <80.00%> (+0.72%) ⬆️
src/JsonPatch.php 99.00% <95.00%> (-1.00%) ⬇️
src/MissingFieldException.php 100.00% <100.00%> (ø)
src/PatchTestOperationFailedException.php 100.00% <100.00%> (ø)
src/PathException.php 100.00% <100.00%> (ø)
src/UnknownOperationException.php 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vearutop vearutop merged commit 4eb3442 into swaggest:master Oct 21, 2022
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.

Improve JsonPatch exceptions

4 participants