denoland/deno · error · TypeError
Mark cannot be negative: received ${mark}
Error message
Mark cannot be negative: received ${mark} What it means
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.
Source
Thrown at ext/web/15_performance.js:162
if (entry.name === name && entry.entryType === type) {
return entry;
}
}
}
function convertMarkToTimestamp(mark) {
if (typeof mark === "string") {
const entry = findMostRecent(mark, "mark");
if (!entry) {
throw new DOMException(
`Cannot find mark: "${mark}"`,
"SyntaxError",
);
}
return entry.startTime;
}
if (mark < 0) {
throw new TypeError(`Mark cannot be negative: received ${mark}`);
}
return mark;
}
function filterByNameType(
name,
type,
) {
return ArrayPrototypeFilter(
performanceEntries,
(entry) =>
(name ? entry.name === name : true) &&
(type ? entry.entryType === type : true),
);
}
const _name = Symbol("[[name]]");
const _entryType = Symbol("[[entryType]]");View on GitHub (pinned to 9ad36f7a2c)
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.
Example fix
// before
performance.measure("m", { start: now - t0 }); // negative when t0 > now
// after
performance.measure("m", { start: Math.max(0, now - t0) }); Defensive patterns
Strategy: validation
Validate before calling
const isNonNegativeNumber = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
function safeMeasureOptions(o = {}) {
return { ...o, start: isNonNegativeNumber(o.start) ? o.start : 0 };
}
performance.measure("m", safeMeasureOptions({ start: now - t0 })); Type guard
const isNonNegativeNumber = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
Prevention
- 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.
When it happens
Trigger: `performance.measure('m', { start: -1 })`; computing `{ end: performance.now() - baseline }` where baseline exceeds now, producing a negative number.
Common situations: Delta arithmetic where end predates start; using Date.now() differences that go negative on clock skew; porting timing code that assumes unsigned inputs.
Related errors
- SyntaxError
- Cannot construct PerformanceMark: startTime cannot be negati
- BenchContext::start() has already been invoked
- ${prefix}Linter plugin name must only contain lowercase lett
- ${prefix}Linter plugin name must start and end with a lowerc
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/8be6e0eb6e332250.
Report an issue: GitHub.