Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KeyNotFoundException not handled by "logErrorAction" #39

Closed
sbiot-aveva opened this issue Jan 13, 2025 · 1 comment · Fixed by #40
Closed

KeyNotFoundException not handled by "logErrorAction" #39

sbiot-aveva opened this issue Jan 13, 2025 · 1 comment · Fixed by #40

Comments

@sbiot-aveva
Copy link
Contributor

Hello!

We are using the JsonPatchDocument.ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter, Action<JsonPatchError>? logErrorAction) method with the expectation that all operation errors will be sent to the logErrorAction handler. However, when an operation attempts to read a dictionary value with a missing key, the KeyNotFoundException bubbles up to our code.

The source of the exception appears to be DictionaryTypedPropertyProxy<TKey, TValue>.GetValue()/DictionaryPropertyProxy.GetValue()

We would like the library to handle that exception like other operation errors and pass it to logErrorAction. I have a fork with changes that I think will fix this issue. Let me know how to proceed, thanks!

Failing Patch Operation Examples:

{
    "op": "test",
    "path": "/DictionaryPropertyName/MissingKey",
    "value": "string"
}
{
    "op": "move",
    "from": "/DictionaryPropertyName/MissingKey",
    "path": "/someExistingProperty"
}
{
    "op": "copy",
    "from": "/DictionaryPropertyName/MissingKey",
    "path": "/someExistingProperty"
}
@Havunen
Copy link
Owner

Havunen commented Jan 13, 2025

PR is welcome if its obviously a bug

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants