diff --git a/src/execution-world/metadata.ts b/src/execution-world/metadata.ts index c76c5ec..547d99e 100644 --- a/src/execution-world/metadata.ts +++ b/src/execution-world/metadata.ts @@ -1,12 +1,8 @@ import { constants } from "node:fs"; import { open } from "node:fs/promises"; -const admissionFailure = ( - code: string, - kind: "file-bytes" | "total-bytes" | "owner-bytes" | "candidates", - measured: number, - limit: number, -) => Object.assign(Error(code), { metadataAdmission: { kind, measured, limit } }); +const admissionFailure = (code: string, kind: "file-bytes", measured: number, limit: number) => + Object.assign(Error(code), { metadataAdmission: { kind, measured, limit } }); /** Admission estimates, not a hard V8 heap limit. A process/cgroup ceiling is * still required. Charge input, parse trees and derived indexes before reading @@ -34,8 +30,7 @@ export class CandidateMetadataBudget { } acquire(owner: string) { if (!owner || owner.length > 4096) throw Error("INVALID_CANDIDATE_METADATA_OWNER"); - if (this.scopes >= this.limits.candidates) - throw admissionFailure("CANDIDATE_METADATA_LIMIT", "candidates", this.scopes + 1, this.limits.candidates); + if (this.scopes >= this.limits.candidates) throw Error("CANDIDATE_METADATA_LIMIT"); this.scopes++; let bytes = 0, closed = false; @@ -43,10 +38,8 @@ export class CandidateMetadataBudget { if (closed) throw Error("CANDIDATE_METADATA_CLOSED"); if (!Number.isSafeInteger(amount) || amount < 0) throw Error("INVALID_CANDIDATE_METADATA_CHARGE"); const owned = this.owners.get(owner) ?? 0; - if (this.bytes + amount > this.limits.bytes) - throw admissionFailure("CANDIDATE_METADATA_LIMIT", "total-bytes", this.bytes + amount, this.limits.bytes); - if (owned + amount > this.limits.ownerBytes) - throw admissionFailure("CANDIDATE_METADATA_LIMIT", "owner-bytes", owned + amount, this.limits.ownerBytes); + if (this.bytes + amount > this.limits.bytes || owned + amount > this.limits.ownerBytes) + throw Error("CANDIDATE_METADATA_LIMIT"); bytes += amount; this.bytes += amount; this.owners.set(owner, owned + amount);