TYPESAFETY: Strict internal typing for AugmentationName (#608)

This commit is contained in:
Snarling
2023-06-16 17:52:42 -04:00
committed by GitHub
parent 12b5c00d14
commit a4b826683e
70 changed files with 2649 additions and 3221 deletions
+9 -5
View File
@@ -28,13 +28,17 @@ class EnumHelper<EnumObj extends object, EnumMember extends Member<EnumObj> & st
if (this.isMember(toValidate)) return toValidate;
// assertString is just called so if the user didn't even pass in a string, they get a different error message
assertString(ctx, argName, toValidate);
// Don't display all possibilities for large enums
let allowableValues = `Allowable values: ${this.valueArray.map((val) => `"${val}"`).join(", ")}`;
if (this.valueArray.length > 10) {
console.warn(
`Provided value ${toValidate} was not a valid option for enum type ${this.name}.\n${allowableValues}`,
);
allowableValues = `See the developer console for allowable values.`;
}
throw helpers.makeRuntimeErrorMsg(
ctx,
`Argument ${argName} should be a ${
this.name
} enum member.\nProvided value: "${toValidate}".\nAllowable values: ${this.valueArray
.map((val) => `"${val}"`)
.join(", ")}`,
`Argument ${argName} should be a ${this.name} enum member.\nProvided value: "${toValidate}".\n${allowableValues}`,
);
}
/** Provides case insensitivty and ignores spaces and dashes, and can always match the input */
+1 -2
View File
@@ -1,7 +1,6 @@
import { AugmentationName } from "@enums";
import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { Player } from "@player";
import { Script } from "../Script/Script";
import { GetAllServers } from "../Server/AllServers";
import { resolveTextFilePath } from "../Paths/TextFilePath";
import { resolveScriptFilePath } from "../Paths/ScriptFilePath";
@@ -137,7 +136,7 @@ export function v1APIBreak(): void {
console.error(`Unexpected error resolving backup path for ${script.filename}`);
continue;
}
server.scripts.set(filename, new Script(filename, script.code, script.server));
server.writeToScriptFile(filename, script.code);
script.code = convert(script.code);
}
}