[api] add a die function and change die to dieWithError