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

  1. Clamp before calling: `Math.max(0, value)`.
  2. Fix the baseline math so computed timestamps are never negative.
  3. 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

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


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/8be6e0eb6e332250. Report an issue: GitHub.