File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @clack/prompts ' : patch
3+ ' @clack/core ' : patch
4+ ---
5+
6+ Add Error support for validate function
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export interface PromptOptions<Self extends Prompt> {
1313 render ( this : Omit < Self , 'prompt' > ) : string | undefined ;
1414 placeholder ?: string ;
1515 initialValue ?: any ;
16- validate ?: ( ( value : any ) => string | undefined ) | undefined ;
16+ validate ?: ( ( value : any ) => string | Error | undefined ) | undefined ;
1717 input ?: Readable ;
1818 output ?: Writable ;
1919 debug ?: boolean ;
@@ -183,7 +183,7 @@ export default class Prompt {
183183 if ( this . opts . validate ) {
184184 const problem = this . opts . validate ( this . value ) ;
185185 if ( problem ) {
186- this . error = problem ;
186+ this . error = problem instanceof Error ? problem . message : problem ;
187187 this . state = 'error' ;
188188 this . rl . write ( this . value ) ;
189189 }
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ export interface TextOptions {
100100 placeholder ?: string ;
101101 defaultValue ?: string ;
102102 initialValue ?: string ;
103- validate ?: ( value : string ) => string | undefined ;
103+ validate ?: ( value : string ) => string | Error | undefined ;
104104}
105105export const text = ( opts : TextOptions ) => {
106106 return new TextPrompt ( {
@@ -136,7 +136,7 @@ export const text = (opts: TextOptions) => {
136136export interface PasswordOptions {
137137 message : string ;
138138 mask ?: string ;
139- validate ?: ( value : string ) => string | undefined ;
139+ validate ?: ( value : string ) => string | Error | undefined ;
140140}
141141export const password = ( opts : PasswordOptions ) => {
142142 return new PasswordPrompt ( {
You can’t perform that action at this time.
0 commit comments