wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
13.48k stars 1.18k forks source link

Improve unknown error handling i Wasp's runtime #2056

Open sodic opened 4 months ago

sodic commented 4 months ago

Tasks

We must:

Context

While working on #2054, I tried to activate the compiler option useUnknownInCatchVariables.. Read the link to understand more.

Turning on this flag reported many errors, as we've used any in all our catch blocks. Updating these catch blocks made it obvious that we have no way of properly handling unexpected exceptions.

For example, after setting useUnknownInCatchVariables, we get the following error:

try {
  // ...
} catch (e) {
    handleApiError(e)
    //            ~~~ Argument of type 'unknown' is not assignable to parameter of type 'AxiosError<...>'
}

It's easily fixable by checking whether the error is an instance of AxiosError:

try {
  // ...
} catch (e) {
  if (e instanceof AxiosError) {
    handleApiError(e)
  }
}

But what if e isn't an instance of AxiosError?

Before, we had a type error of sending a potential unknown error into a function that can't handle it. Now, we would be ignoring the unknown error entirely.

The correct solution would be something like:

try {
  // ...
} catch (e) {
  if (e instanceof AxiosError) {
    handleApiError(e)
  } else {
    handleUnknownError(e)
}

Unfortunately, we don't have anything that can act as handleUnknownError.