{"record":{"id":"55c6672664a50ba5","repo":"denoland/deno","slug":"failed-to-construct-quotaexceedederror-quota-mu","errorCode":null,"errorMessage":"Failed to construct 'QuotaExceededError': quota must not be negative","messagePattern":"Failed to construct 'QuotaExceededError': quota must not be negative","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/web/01_dom_exception.js","lineNumber":285,"sourceCode":"\n// Defined in WebIDL 4.3.1.\n// https://webidl.spec.whatwg.org/#quotaexceedederror\nclass QuotaExceededError extends DOMException {\n  [_quota];\n  [_requested];\n\n  constructor(message = \"\", options = { __proto__: null }) {\n    super(message, \"QuotaExceededError\");\n\n    if (options !== null && typeof options === \"object\") {\n      if (ObjectHasOwn(options, \"quota\")) {\n        const quota = webidl.converters[\"unrestricted double\"](\n          options.quota,\n          \"Failed to construct 'QuotaExceededError'\",\n          \"'quota' member of QuotaExceededErrorOptions\",\n        );\n        if (quota < 0) {\n          throw new RangeError(\n            \"Failed to construct 'QuotaExceededError': quota must not be negative\",\n          );\n        }\n        this[_quota] = quota;\n      } else {\n        this[_quota] = null;\n      }\n      if (ObjectHasOwn(options, \"requested\")) {\n        const requested = webidl.converters[\"unrestricted double\"](\n          options.requested,\n          \"Failed to construct 'QuotaExceededError'\",\n          \"'requested' member of QuotaExceededErrorOptions\",\n        );\n        if (requested < 0) {\n          throw new RangeError(\n            \"Failed to construct 'QuotaExceededError': requested must not be negative\",\n          );\n        }","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/01_dom_exception.js#L267-L303","documentation":"QuotaExceededError (ext/web/01_dom_exception.js:285, defined per WebIDL 4.3.1) is constructible in Deno with an options bag exposing quota/requested details. The 'quota' member is converted to an unrestricted double and must not be negative; a negative value throws this RangeError from the constructor, so the exception object is never produced.","triggerScenarios":"new QuotaExceededError('msg', { quota: -1 }); quota computed as limit - used underflowing below zero; passing a -1 sentinel meaning 'unknown'; forwarding unvalidated user input into the options bag.","commonSituations":"Wrapping storage/quota reporting APIs (e.g. navigator.storage.estimate style flows) that surface a QuotaExceededError with details; libraries using negative sentinels for missing values; unit tests probing constructor validation.","solutions":["Omit the quota member when unknown; it defaults to null","Clamp before constructing: Math.max(0, quota)","Validate the options bag with a guard so callers get your own error message instead of the constructor's"],"exampleFix":"// before\nthrow new QuotaExceededError('storage full', { quota: limit - used }); // can be -1\n\n// after\nthrow new QuotaExceededError('storage full', {\n  quota: Math.max(0, limit - used),\n});","handlingStrategy":"validation","validationCode":"if (quota !== undefined && !(typeof quota === \"number\" && quota >= 0)) {\n  throw new RangeError(\"quota must be a non-negative number\");\n}\nthrow new QuotaExceededError(msg, { quota });","typeGuard":"const isNonNegativeNumber = (v: unknown): v is number =>\n  typeof v === \"number\" && Number.isFinite(v) && v >= 0;","tryCatchPattern":"try {\n  throw new QuotaExceededError(msg, options);\n} catch (e) {\n  if (e instanceof RangeError && e.message.includes(\"quota must not be negative\")) {\n    throw new QuotaExceededError(msg); // omit the details member\n  }\n  throw e;\n}","preventionTips":["Clamp computed quota values with Math.max(0, x)","Use null/omission instead of -1 sentinels for unknown quota","Validate the whole options bag once before constructing the error"],"tags":["dom-exception","quota","storage","validation"],"backgroundTag":"negative-value-rejected","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}