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.

Bug: uvu is not detecting a thrown string

See original GitHub issue

In #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:open
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lukeedcommented, Aug 10, 2021

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 way goto works in other languages. Errors are Errors.

Tbh my inclination is to close this as unsupported, but going to play with it first.

1reaction
jasikparkcommented, Aug 11, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

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