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.

Self-referential objects break decoders

See original GitHub issue

If an object is passed in that refers to itself (like the express req object), an infinite loop occurs.

Smallest reproducible example:

const { string } = require('decoders');

// Take any decoder and pass in some self-referential object
const req = {};
req.myself = req;

console.log(string(req)); // <--- RangeError: Maximum call stack size exceeded

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nviecommented, May 22, 2020

Default error messages are kinda broken when this large anyways.

If you want more succinct error messages, try using guard(..., { style: 'simple' }) instead of just the default guard(...). That will not echo back the input object, and just describe where the error is. That won’t help you with this issue, but may help reduce your error messages in case of large objects.

1reaction
sfarthincommented, May 22, 2020

Thanks for the good work on this library, its an essential tool when working with types in JS/TS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Built-in decoders
This decoder is optimized for tagged unions, i.e. a union of objects where one field is used as the discriminator. Decoding now works...
Read more >
Self-Referential Classes/Linked Objects
In this lecture we will begin studying self-referential classes, which leaded to linked objects. Initially we will discuss in great detail the simplest...
Read more >
Self-reference - Wikipedia
Self-reference occurs in natural or formal languages when a sentence, idea or formula refers to itself. The reference may be expressed either ...
Read more >
Improving self-referential structs - language design
I'm the author of a crate called rental, designed to enable the declaration of self-borrowing structs. I've tried as hard as I could...
Read more >
Managing self and cancellable references when using Combine
How to avoid common memory-related issues when working with self and cancellable references within the context of Combine.
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