Skip to content

Commit ee8be2e

Browse files
authoredFeb 5, 2023
fix(Args): ensure proper error types are always thrown (#601)
This changes the `result.unwrap()` calls to `result.unwrapRaw()` to ensure that the erorr that gets thrown for the following methods: - `args.pick(...)` - `args.rest(...)` - `args.repeat(...)` - `args.peek(...)` This makes it so that the error that ends up in `messageCommandError` listener will have the proper error type. Furthermore, it can also be handled properly when chaining `.catch()` calls to the `args.X` method. resolves #528
1 parent 18ad9fa commit ee8be2e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎src/lib/parsers/Args.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class Args {
172172
public async pick<K extends keyof ArgType>(type: K, options?: ArgOptions): Promise<ArgType[K]>;
173173
public async pick<K extends keyof ArgType>(type: K, options?: ArgOptions): Promise<ArgType[K]> {
174174
const result = await this.pickResult(type, options);
175-
return result.unwrap();
175+
return result.unwrapRaw();
176176
}
177177

178178
/**
@@ -259,7 +259,7 @@ export class Args {
259259
public async rest<K extends keyof ArgType>(type: K, options?: ArgOptions): Promise<ArgType[K]>;
260260
public async rest<K extends keyof ArgType>(type: K, options?: ArgOptions): Promise<ArgType[K]> {
261261
const result = await this.restResult(type, options);
262-
return result.unwrap();
262+
return result.unwrapRaw();
263263
}
264264

265265
/**
@@ -299,6 +299,7 @@ export class Args {
299299
if (this.parser.finished) return this.missingArguments();
300300

301301
const output: ArgType[K][] = [];
302+
302303
for (let i = 0, times = options.times ?? Infinity; i < times; i++) {
303304
const result = await this.parser.singleParseAsync(async (arg) =>
304305
argument.run(arg, {
@@ -310,6 +311,7 @@ export class Args {
310311
...options
311312
})
312313
);
314+
313315
if (result.isErr()) {
314316
const error = result.unwrapErr();
315317
if (error === null) break;
@@ -356,7 +358,7 @@ export class Args {
356358
public async repeat<K extends keyof ArgType>(type: K, options?: RepeatArgOptions): Promise<ArgType[K][]>;
357359
public async repeat<K extends keyof ArgType>(type: K, options?: RepeatArgOptions): Promise<ArgType[K][]> {
358360
const result = await this.repeatResult(type, options);
359-
return result.unwrap();
361+
return result.unwrapRaw();
360362
}
361363

362364
/**
@@ -508,7 +510,7 @@ export class Args {
508510
public async peek<K extends keyof ArgType>(type: (() => Argument.Result<ArgType[K]>) | K, options?: ArgOptions): Promise<ArgType[K]>;
509511
public async peek<K extends keyof ArgType>(type: (() => Argument.Result<ArgType[K]>) | K, options?: ArgOptions): Promise<ArgType[K]> {
510512
const result = await this.peekResult(type, options);
511-
return result.unwrap();
513+
return result.unwrapRaw();
512514
}
513515

514516
/**

0 commit comments

Comments
 (0)
Please sign in to comment.