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

Structured errors #100

Open
dleavitt opened this issue May 21, 2019 · 1 comment
Open

Structured errors #100

dleavitt opened this issue May 21, 2019 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@dleavitt
Copy link

dleavitt commented May 21, 2019

The current error format is good for reading in the console, but is not very suitable for sending to error reporting services or otherwise dealing with in a programmatic way, as it's a big string.

Instead, could throw an error subclass with the same fields as the message uses, something like:

{ 
  classId: instance[Settings.CLASS_IDENTIFIER],
  classProperty: classPropertyName,
  classPropertyValue: classInstancePropertyValue,
  expectedType: this.getExpectedType(expectedJsonType),
  runtimeType: this.getTrueType(classInstancePropertyValue),
  jsonProperty: jsonPropertyName,
  jsonValue: value,
  children: e.jsonConvertErrorDetails, // nested child errors
}

Some other things that seem pretty useful for both error reporting and readability:

  1. Have the option to omit the "JSON value" from the error message / hypothetical error properties above. For errors in the leaves of nested json structures, this property can make the error pretty unwieldy.
  2. Consider displaying errors from the top-down instead of the bottom-up, with the leaf error displayed first. This is usually what you're interested in.
  3. If adding the above properties, consider an option to simplify the displayed messages to just the heading of the lowermost error. For instance, if you're fetching an array of blog posts and one of them is bad, error.message would just be: "Fatal error in JsonConvert. Failed to map the JSON object to the class "BlogPost" because the defined JSON property "title" does not exist".
@andreas-aeschlimann andreas-aeschlimann self-assigned this May 21, 2019
@andreas-aeschlimann andreas-aeschlimann added the enhancement New feature or request label May 21, 2019
@andreas-aeschlimann
Copy link
Member

Hey, thanks for your input. In fact I had already something like this in mind for the next major release. I'll keep this issue open so we'll make sure that it is included in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants