Skip to content

2.0.0

Compare
Choose a tag to compare
@musicq musicq released this 18 May 06:43
· 72 commits to main since this release

Changes

Won't exit by default in Node

  1. Error won't exit the program by default, instead, it will throw an error

In v1.x, when you try to unwrap a Result that is an error, the program will exit by default in Node. In most cases or a strong system, you may want to handle the error by yourself.

In v2, you can set a customized panic function by using the function setPanic. When an error occurs, it will call your customized panic function, then you can handle it somewhere.

class MyError extends Error {}

setPanic((msg: string) => {
  throw new MyError(msg)
})

However, you can still exit the program by specifying the option panic: true.

err('some error').unwrap({panic: true})

NOTE that you should implement the exit behavior by yourself if you are using customized panic function.