Capture key name in reader exception where applicable
See original GitHub issueIt would be very helpful to be able to generate a tiny bit more user friendly error messages that include the key in case of a value parsing error, so it’s easier for myself, but also an enduser to correct any input errors.
i.e. when a LocalDate
has a wrong format, the following exception message is thrown:
expected digit, offset: 0x0000012d
Looking at the macro generated code:
case 752419634 => if (in.isCharBufEqualsTo(l, "tradeDate"))
{
if (p0.&(65536).!=(0))
p0.^=(65536)
else
in.duplicatedKeyError(l);
_tradeDate = in.readLocalDate(_tradeDate)
}
I think there is an opportunity to wrap the last call (or the whole block that’s in the while loop) in a separate try/catch and enrich the thrown exception with the key name (tradeDate
in this case).
The fact that the user knows which key has an error usually is enough. The error message itself can stay technical.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >Python | How to catch file not readable exceptions
Problem i am trying to solve is - Read a CSV file, check if a variable within CSV file is of certain value...
Read more >Everything you wanted to know about exceptions - PowerShell
You can easily handle exceptions generated by other people's code or you can ... Here is a quick overview of some of the...
Read more >Exception Handling in Java - DigitalOcean
Introduction. An exception is an error event that can happen during the execution of a program and disrupts its normal flow.
Read more >Built-in Exceptions — Python 3.11.1 documentation
This applies only to unqualified names. The associated value is an error message that includes the name that could not be found. The...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just wanted to leave a comment that I haven’t forgotten about this, but also haven’t looked into or thought about a way to make the error messages more user friendly. I’ll still keep using jsoniter-scala anyway, as it just works nicest of them all I think. Maybe, considering jsoniter-scala should stay high performance, it’s even an option to have an alternative parser that has very good error handling, and do a second parsing round with that one in case of errors. The performance penalty in an error case usually doesn’t matter anyway.
What worries me is the default behavior, though. I think we can improve it without compromising performance.