Bug: uvu is not detecting a thrown string
See original GitHub issueIn #129 there’s a function call that is only detected by uvu if i catch and rethrow it, it just fails to complete the test suite otherwise.
by altering the test to this:
Prettier('can format a basic Astro file', async () => { const [src, out] = await getFiles('basic'); assert.not.fixture(src, out); console.log('before format'); try { const formatted = format(src); } catch (e) { if (typeof e == 'Error') { throw e; } throw new Error(e); } console.log('after format'); assert.fixture(formatted, out); });
I can get the suite to run correctly… I’m not sure why it’s failing there.
https://github.com/lukeed/uvu/issues/129#issuecomment-894937138
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
uvu doesn't detect thrown strings - CodeSandbox
We had trouble connecting to the server, try restarting it or check the logs to see what happened. Terminal.
Read more >uvu: Versions | Openbase
Full version history for uvu including change logs. ... (diff) Ensure multi-line string vs non-string does not throw TypeError (#26): e9f5148 ...
Read more >uvu-expect - npm Package Health Analysis - Snyk
Checks whether a function throws. Every assertion done after this (if not negated) happens on the thrown value. Alias: .throw const throwFn = ......
Read more >javascript - Throwing strings instead of Errors - Stack Overflow
A string is not an error object, and does not convey any useful debugging information. Devtools rely on that, such as the file...
Read more >Utah Valley University
UVU's unique model focuses on student success. Through engaged learning, rigorous academic programs, and faculty-mentored research, UVU is transforming ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes I know. I’m keeping this open as an exploration to see if it even makes sense to throw non-Errors.
The entirety of uvu operates with Error primitives. That’s how assertion control is orchestrated. Throwing things that are not Errors is not the same thing as throwing an Error. In other words,
throw
on its own is not exclusively a “this is an error” – it’s a way to abort and bubble up any value, kinda the same waygoto
works in other languages. Errors are Errors.Tbh my inclination is to close this as unsupported, but going to play with it first.
I would say that if you end up not supporting detecting non-Error() throws, that should be added to the documentation with a recommendation for how to correctly catch and rethrow them for uvu.
Because I agree that encouraging Error() use is a good idea, but I haven’t encountered many examples of using
throw
for things other than error reporting, even if it’s via a raw string - maybe it could catch other values and print a warning that they aren’t true errors, but are strings, so they should be changed