Ensure all our catch blocks properly handle unknown errors.
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.
Tasks
We must:
handleUnknownError
useUnknownInCatchVariables
. inside SDK, web app, and server.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:It's easily fixable by checking whether the error is an instance of
AxiosError
:But what if
e
isn't an instance ofAxiosError
?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:
Unfortunately, we don't have anything that can act as
handleUnknownError
.