From eb45c2c8bfd1f272ea98ea81ddcc374875758d94 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Mon, 2 Aug 2021 22:02:45 +0200 Subject: [PATCH] Argument errors --- src/Arguments.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Arguments.ts b/src/Arguments.ts index 5cd8ef9..09a737e 100644 --- a/src/Arguments.ts +++ b/src/Arguments.ts @@ -1,3 +1,5 @@ +import { ArgumentTypeError } from "./Error.js"; + export type ArgumentType = "STRING" | "BOOLEAN" | "INTEGER" | "FLOAT"; export type ArgumentResolvable = string | boolean | number; export interface Argument { @@ -15,18 +17,14 @@ export const ProcessArgument = ( case "INTEGER": const numI = parseInt(a); if (isNaN(numI)) { - throw new TypeError( - `Argument ${a} cannot be converted to ${type}` - ); + throw new ArgumentTypeError(a, type); } else { return numI; } case "FLOAT": const numF = parseFloat(a); if (isNaN(numF)) { - throw new TypeError( - `Argument ${a} cannot be converted to ${type}` - ); + throw new ArgumentTypeError(a, type); } else { return numF; } @@ -36,9 +34,7 @@ export const ProcessArgument = ( } else if (a.toLowerCase() == "false") { return false; } else { - throw new TypeError( - `Argument ${a} cannot be converted to ${type}` - ); + throw new ArgumentTypeError(a, type); } default: throw new TypeError("Invalied type specified");