{"record":{"id":"8be6e0eb6e332250","repo":"denoland/deno","slug":"mark-cannot-be-negative-received-mark","errorCode":null,"errorMessage":"Mark cannot be negative: received ${mark}","messagePattern":"Mark cannot be negative: received (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/web/15_performance.js","lineNumber":162,"sourceCode":"    if (entry.name === name && entry.entryType === type) {\n      return entry;\n    }\n  }\n}\n\nfunction convertMarkToTimestamp(mark) {\n  if (typeof mark === \"string\") {\n    const entry = findMostRecent(mark, \"mark\");\n    if (!entry) {\n      throw new DOMException(\n        `Cannot find mark: \"${mark}\"`,\n        \"SyntaxError\",\n      );\n    }\n    return entry.startTime;\n  }\n  if (mark < 0) {\n    throw new TypeError(`Mark cannot be negative: received ${mark}`);\n  }\n  return mark;\n}\n\nfunction filterByNameType(\n  name,\n  type,\n) {\n  return ArrayPrototypeFilter(\n    performanceEntries,\n    (entry) =>\n      (name ? entry.name === name : true) &&\n      (type ? entry.entryType === type : true),\n  );\n}\n\nconst _name = Symbol(\"[[name]]\");\nconst _entryType = Symbol(\"[[entryType]]\");","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/15_performance.js#L144-L180","documentation":"When a numeric timestamp is passed to performance.measure options (start/end/duration), `convertMarkToTimestamp` rejects negative numbers with TypeError `Mark cannot be negative: received <mark>` (ext/web/15_performance.js:161-164). Only non-negative numbers and resolvable mark-name strings are valid inputs.","triggerScenarios":"`performance.measure('m', { start: -1 })`; computing `{ end: performance.now() - baseline }` where baseline exceeds now, producing a negative number.","commonSituations":"Delta arithmetic where end predates start; using Date.now() differences that go negative on clock skew; porting timing code that assumes unsigned inputs.","solutions":["Clamp before calling: `Math.max(0, value)`.","Fix the baseline math so computed timestamps are never negative.","Validate numeric options with a shared guard in your measurement helpers."],"exampleFix":"// before\nperformance.measure(\"m\", { start: now - t0 }); // negative when t0 > now\n\n// after\nperformance.measure(\"m\", { start: Math.max(0, now - t0) });","handlingStrategy":"validation","validationCode":"const isNonNegativeNumber = (v) => typeof v === \"number\" && Number.isFinite(v) && v >= 0;\nfunction safeMeasureOptions(o = {}) {\n  return { ...o, start: isNonNegativeNumber(o.start) ? o.start : 0 };\n}\nperformance.measure(\"m\", safeMeasureOptions({ start: now - t0 }));","typeGuard":"const isNonNegativeNumber = (v) => typeof v === \"number\" && Number.isFinite(v) && v >= 0;","tryCatchPattern":null,"preventionTips":["Clamp computed timestamps with Math.max(0, x) before passing them.","Compute durations as end - start with operands in the right order.","Validate start/end/duration in one shared helper used by all measure calls."],"tags":["performance","user-timing","validation"],"backgroundTag":"performance-timestamp-invalid","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}