mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
API: Make ns.codingcontract.createDummyContract throw error if type is invalid (#2188)
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user