mdbetancourt / eslint-plugin-neverthrow

MIT License
44 stars 4 forks source link

Allow handling errors with isOk/else or isErr #9

Open dominic-simplan opened 2 years ago

dominic-simplan commented 2 years ago

Shouldn't it be allowed to handle errors with an if/else block and the isOk/isErr functions? E.g. these should now throw an error:

const result = getResult();
if (result.isOk()) {
   ...
}
else {
   // Error handled here
}
const result = getResult();
if (result.isErr()) {
   // Error handled here
}
slavistan commented 2 years ago

I second that. Sometimes I just need to return the value if isOk() is fulfilled and to handle the error otherwise. match() etc. is no use here.

const result = foo()
if (result.isOk()) {
    return result.value
}
if (result.error instance of MyError) {
    // handle errors
} else if ...
supermacro commented 2 years ago

I personally don't have the bandwidth to fix this - PRs are always welcome!

Bistard commented 10 months ago

I think I can make a PR with that. Is this repository still maintaining?