Is your feature request related to a problem? Please describe.
I would like to create custom errors, and return they on validate, without the need to call error.message every time.
Describe the solution you'd like
Make prompt.validate accept Error instances as return type. Then internally prompt.validate could verify if the result is a Error instance, then call error.message.
Example:
interface TextOptions {
message: string;
...
validate?: (value: string) => string | Error | void;
}
await p.text({
message: 'Type your alias key:',
validate: value => {
if(value.length !== 1) {
return new InvalidParamError('alias', 'max length is 1')
}
}
})
Describe alternatives you've considered
N/A
Additional context
I'd be happy to contribute this.
Is your feature request related to a problem? Please describe. I would like to create custom errors, and return they on validate, without the need to call
error.message
every time.Describe the solution you'd like Make
prompt.validate
acceptError
instances as return type. Then internallyprompt.validate
could verify if the result is aError
instance, then callerror.message
.Example:
Describe alternatives you've considered N/A
Additional context I'd be happy to contribute this.