[Request] Add `Error` support for `prompt.validate`
Mist3rBru opened this issue · comments
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.