-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Allow lazy message
#47
base: main
Are you sure you want to change the base?
Conversation
Sometimes calculating error messages is costly |
Sometimes calculating an error message when there is no error will make an error. |
Thanks for the addition but this should be implemented in Node.js first. I did think about something like that before as well but just accepting any function would prevent other usages for this variable. I'll soon have a look at it to implement something like this or please feel free to open a PR in Node.js directly. |
@BridgeAR |
@BridgeAR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a great API; the user can already pass { toString() { return 'lazy message'; } }
if they like. if we wanted to allow them to pass a getter function for message (which i'm not convinced by either), then i'd think that should be a separate option rather than overloading message
.
This module is a port of Node.js's |
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
See #47 (comment)
The
The This problem is something that I ran into myself before as well and I think it's a good idea to implement something like this in general. The specific implementation aside. I thought about adding a new assertion function which may be passed through as lazy message: const assert = require('assert').strict
assert.deepEqual(foo, bar, assert.lazy(() => 'I am a lazy message'))` That way it's at least expressive for someone else who reads the code and functions won't be special handled in general. What do you think about that solution? |
I don't even really understand the use case where the message is expensive to compute; but in that case I think a differently-named option would be ideal. |
@ljharb we had expensive messages in Node.js before: We compared some entries of a complex structure and in case of an error we'd inspect the structure to know how it looked like. That caused some tests to time out at some point due to inspecting multiple megabytes for lots of test cases instead of only inspecting the object in case of an error. How would your ideal API look like in that case? I tried to outline the limited possibilities right now. |
We can bikeshed the name, but some straightforward option like “getMessage” - it'd throw if both that and message were provided, and if getMessage was not a function, and it’d invoke the function when it needed to display the message. |
No description provided.