Skip to content

Commit

Permalink
feat(args): pass more context to args errors (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Feb 9, 2021
1 parent fa60b13 commit 007eaed
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/parsers/Args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,19 +627,26 @@ export class Args {
return this.parser.finished;
}

/**
* Defines the `JSON.stringify` override.
*/
public toJSON() {
return { message: this.message, command: this.command, commandContext: this.commandContext };
}

protected unavailableArgument<T>(type: string | IArgument<T>) {
const name = typeof type === 'string' ? type : type.name;
return err(
new UserError({
identifier: Identifiers.ArgsUnavailable,
message: `The argument "${name}" was not found.`,
context: { name }
context: { name, ...this.toJSON() }
})
);
}

protected missingArguments() {
return err(new UserError({ identifier: Identifiers.ArgsMissing, message: 'There are no more arguments.' }));
return err(new UserError({ identifier: Identifiers.ArgsMissing, message: 'There are no more arguments.', context: this.toJSON() }));
}

/**
Expand Down

0 comments on commit 007eaed

Please sign in to comment.