Skip to content

Commit

Permalink
feat(arguments): more descriptive error messages (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler J Russell <22531310+Nytelife26@users.noreply.github.com>
Co-authored-by: Jeroen Claassens <support@favware.tech>
  • Loading branch information
3 people authored Jan 3, 2021
1 parent 9ca7456 commit 04931bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/arguments/CoreFloat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export class CoreArgument extends Argument<number> {
return this.error(argument, 'ArgumentFloatInvalidFloat', 'The argument did not resolve to a valid floating point number.');
}
if (typeof context.minimum === 'number' && parsed < context.minimum) {
return this.error(argument, 'ArgumentFloatTooSmall', 'The argument is too small.');
return this.error(argument, 'ArgumentFloatTooSmall', `The argument must be greater than ${context.minimum}.`);
}
if (typeof context.maximum === 'number' && parsed > context.maximum) {
return this.error(argument, 'ArgumentFloatTooBig', 'The argument is too big.');
return this.error(argument, 'ArgumentFloatTooBig', `The argument must be less than ${context.maximum}.`);
}

return this.ok(parsed);
Expand Down
4 changes: 2 additions & 2 deletions src/arguments/CoreInteger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export class CoreArgument extends Argument<number> {
return this.error(argument, 'ArgumentIntegerInvalidNumber', 'The argument did not resolve to an integer.');
}
if (typeof context.minimum === 'number' && parsed < context.minimum) {
return this.error(argument, 'ArgumentIntegerTooSmall', 'The argument is too small.');
return this.error(argument, 'ArgumentIntegerTooSmall', `The argument must be greater than ${context.minimum}.`);
}
if (typeof context.maximum === 'number' && parsed > context.maximum) {
return this.error(argument, 'ArgumentIntegerTooBig', 'The argument is too big.');
return this.error(argument, 'ArgumentIntegerTooBig', `The argument must be less than ${context.maximum}.`);
}

return this.ok(parsed);
Expand Down
4 changes: 2 additions & 2 deletions src/arguments/CoreString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export class CoreArgument extends Argument<string> {

public run(argument: string, context: ArgumentContext): ArgumentResult<string> {
if (typeof context.minimum === 'number' && argument.length < context.minimum) {
return this.error(argument, 'ArgumentStringTooShort', 'The argument is too short.');
return this.error(argument, 'ArgumentStringTooShort', `The argument must be greater than ${context.minimum} characters.`);
}
if (typeof context.maximum === 'number' && argument.length > context.maximum) {
return this.error(argument, 'ArgumentStringTooLong', 'The argument is too long.');
return this.error(argument, 'ArgumentStringTooLong', `The argument must be less than ${context.maximum} characters.`);
}

return this.ok(argument);
Expand Down

0 comments on commit 04931bc

Please sign in to comment.