Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Create a hook for intercepting serialisiation errors #1333

Open
nrobi144 opened this issue Dec 11, 2024 · 1 comment
Open

Create a hook for intercepting serialisiation errors #1333

nrobi144 opened this issue Dec 11, 2024 · 1 comment
Assignees
Labels

Comments

@nrobi144
Copy link

Use-Case

We don't just want to provide a default value in case certain fields can't be parsed or are not present in the JSON. But also intercept these issues so we can log & monitor it, when it happens.

Example DSLs

1)

abstract class MyValue {
  @BuiltValueHook(<deserializationError>: true)
  static void _logError(MyValueBuilder b, Exception e, String key) => logger.logError(ParsingError(e, key))

or maybe even better would be to do the same globally

2) A global plugin that logs all deserialization exceptions 🤔

This is assuming if @nullable is used and if that field can't be parsed, the value will be null and now exceptions will be thrown

@davidmorgan
Copy link
Collaborator

This looks related to #1293.

I think catching DeserializationError is something you can already do? Either by wrapping your RPC handling code in try/catch or by installing a Zone error handler to catch them.

@davidmorgan davidmorgan self-assigned this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants