Error Handling

[ERROR] Encountered error on message command "test" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\commands\Developer\test.js" Anyway of removing these error messages if the type of the error is a string? I don't want this error showing up on console when I do stuff like, for example:
if (something) throw 'some error here'
if (something) throw 'some error here'
Solution:
I opened a PR to add an example
Jump to solution
6 Replies
Favna
Favna•5mo ago
Well first of all this exists even if you don't use it right now: https://eslint.org/docs/latest/rules/no-throw-literal Secondly, no because literal errors are still error classes. What you can do however is
class LiteralError extends Error {
}
class LiteralError extends Error {
}
Then throw a new LiteralError and detect it with if (error instanceof LiteralError)
no-throw-literal - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
kyra
kyra•5mo ago
Alternatively, you can use UserError from Sapphire
-Carlosđź‘‘
-Carlos👑•5mo ago
is there any documentation for it
kyra
kyra•5mo ago
Solution
kyra
kyra•5mo ago
I opened a PR to add an example
-Carlosđź‘‘
-Carlos👑•5mo ago
alright ty