Skip to content

Structured errors #100

Open
Open
@dleavitt

Description

@dleavitt

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".

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions