question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Capture key name in reader exception where applicable

See original GitHub issue

It 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:open
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
momaniacommented, Jan 30, 2020

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.

0reactions
jvicancommented, Feb 14, 2020

What worries me is the default behavior, though. I think we can improve it without compromising performance.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found