API: Make ns.codingcontract.createDummyContract throw error if type is invalid (#2188)

This commit is contained in:
catloversg
2025-06-21 02:08:49 +07:00
committed by GitHub
parent 00e2169c92
commit 1eca42c75e
5 changed files with 9 additions and 12 deletions
+2 -4
View File
@@ -5,9 +5,9 @@ import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers";
import { CodingContractName } from "@enums";
import { generateDummyContract } from "../CodingContract/ContractGenerator";
import { isCodingContractName } from "../CodingContract/ContractTypes";
import { type BaseServer } from "../Server/BaseServer";
import { exceptionAlert } from "../utils/helpers/exceptionAlert";
import { getEnumHelper } from "../utils/EnumHelper";
export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
const getCodingContract = function (ctx: NetscriptContext, hostname: string, filename: string): CodingContract {
@@ -128,9 +128,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
return contract.getMaxNumTries() - contract.tries;
},
createDummyContract: (ctx) => (_type) => {
const type = helpers.string(ctx, "type", _type);
if (!isCodingContractName(type))
return helpers.errorMessage(ctx, `The given type is not a valid contract type. Got '${type}'`);
const type = getEnumHelper("CodingContractName").nsGetMember(ctx, _type);
return generateDummyContract(type);
},
getContractTypes: () => () => Object.values(CodingContractName),