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.

Throws on invalid dates

See original GitHub issue
> require('msgpackr').encode(new Date('invalid'))
Uncaught:
RangeError: The number NaN cannot be converted to a BigInt because it is not an integer
    at BigInt (<anonymous>)
    at Packr.pack (.../node_modules/msgpackr/dist/node.cjs:1627:41)
    at pack (.../node_modules/msgpackr/dist/node.cjs:1355:34)
    at Object.Packr.pack.encode (.../node_modules/msgpackr/dist/node.cjs:1101:5)

> require('cbor-x').encode(new Date('invalid'))
<Buffer c1 fb 7f f8 00 00 00 00 00 00>

> require('@msgpack/msgpack').encode(new Date('invalid'))
Uint8Array(15) [
  199, 12, 255, 0, 0, 0,
    0,  0,   0, 0, 0, 0,
    0,  0,   0
]

> require('msgpack-lite').encode(new Date('invalid'))
<Buffer c7 09 0d cb 7f f8 00 00 00 00 00 00>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kriszypcommented, Nov 16, 2021

Yes, a better error message certainly seems appropriate. I can certainly just come up with a invalid date representation. It probably would be reasonable to use the MessagePack timestamp code (-1), with zero length data to represent an invalid date. And would probably use a flag for this since it seems like most users prefer predictable fail-fast behavior. But this is a good suggestion, I will take a look at this.

0reactions
kriszypcommented, Nov 19, 2021

Published in v1.5.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to throw an error whenever an invalid date object is ...
Create a factory type function which throws an error if the string given produces an invalid date, but returns the date if it's...
Read more >
RangeError: invalid date - JavaScript - MDN Web Docs
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date or Date.parse() .
Read more >
Throw an error on invalid dates #455 - moment/luxon - GitHub
Is there a way to have luxon throw Errors when parsing invalid dates? The text was updated successfully, but these errors were encountered: ......
Read more >
new Date("2018-06-19") throws invalid date error - ServiceNow
I am reading the date from a variable as this. Ideally it should be supported, just not sure why it's not.
Read more >
Invalid date/time issue in Apex Code
In the apex class, I am trying to populate this date on the Asset object. Below is my code. Datetime effectiveDt = Datetime.parse(wsResponse....
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