Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept generator function for error message #62

Closed
davidje13 opened this issue Apr 19, 2020 · 4 comments
Closed

Accept generator function for error message #62

davidje13 opened this issue Apr 19, 2020 · 4 comments

Comments

@davidje13
Copy link

For dev-time error messages (and for those not using build-time rewriters), it would be nice if time-consuming calculations for error messages were only performed in the event of an error. This would be easy to achieve with minimal bloat using a lambda:

invariant(something, () => `my message with ${complex()} calculations`)

The build-time rewriters will be able to strip this with no changes necessary.

Internally:

throw new Error(`${prefix}: ${typeof message == 'function' ? message() : message || ''}`);
@alexreardon
Copy link
Owner

🤔

@alexreardon
Copy link
Owner

How does this look @davidje13? https://github.com/alexreardon/tiny-invariant/pull/76/files

@alexreardon
Copy link
Owner

Closed by mistake

@alexreardon
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants