Argument errors

This commit is contained in:
mmacierzanka committed 2021-08-02 22:02:45 +02:00
1 parent 781472a200
commit eb45c2c8bf
1 file changed
+5 -9
+5 -9
View File
@@ -1,3 +1,5 @@
import { ArgumentTypeError } from "./Error.js";
export type ArgumentType = "STRING" | "BOOLEAN" | "INTEGER" | "FLOAT"; export type ArgumentType = "STRING" | "BOOLEAN" | "INTEGER" | "FLOAT";
export type ArgumentResolvable = string | boolean | number; export type ArgumentResolvable = string | boolean | number;
export interface Argument { export interface Argument {
@@ -15,18 +17,14 @@ export const ProcessArgument = (
case "INTEGER": case "INTEGER":
const numI = parseInt(a); const numI = parseInt(a);
if (isNaN(numI)) { if (isNaN(numI)) {
throw new TypeError( throw new ArgumentTypeError(a, type);
`Argument ${a} cannot be converted to ${type}`
);
} else { } else {
return numI; return numI;
} }
case "FLOAT": case "FLOAT":
const numF = parseFloat(a); const numF = parseFloat(a);
if (isNaN(numF)) { if (isNaN(numF)) {
throw new TypeError( throw new ArgumentTypeError(a, type);
`Argument ${a} cannot be converted to ${type}`
);
} else { } else {
return numF; return numF;
} }
@@ -36,9 +34,7 @@ export const ProcessArgument = (
} else if (a.toLowerCase() == "false") { } else if (a.toLowerCase() == "false") {
return false; return false;
} else { } else {
throw new TypeError( throw new ArgumentTypeError(a, type);
`Argument ${a} cannot be converted to ${type}`
);
} }
default: default:
throw new TypeError("Invalied type specified"); throw new TypeError("Invalied type specified");