Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add Error support for prompt.validate #160

Open
Mist3rBru opened this issue Sep 4, 2023 · 0 comments · May be fixed by #165
Open

[Request] Add Error support for prompt.validate #160

Mist3rBru opened this issue Sep 4, 2023 · 0 comments · May be fixed by #165
Labels
enhancement New feature or request

Comments

@Mist3rBru
Copy link
Contributor

Mist3rBru commented Sep 4, 2023

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.

@Mist3rBru Mist3rBru added the enhancement New feature or request label Sep 4, 2023
@Mist3rBru Mist3rBru changed the title [Request] Add Error support forprompt.validate [Request] Add Error support for prompt.validate Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant