NativeScript/NativeScript · error · Error

Timer ${name} paused more times than started.

Error message

Timer ${name} paused more times than started.

What it means

The profiling module tracks timers created with timer(name)/start(name). stop(name) increments internal pause accounting; throwing here means stop() (or pause accounting) was called more times than the timer was started, so the timing state is inconsistent. It guards against unbalanced start/stop pairs in profiling code.

Source

Thrown at packages/core/profiling/index.ts:74

export function stop(name: string): TimerInfo {
	const info = timers[name];

	if (!info) {
		throw new Error(`No timer started: ${name}`);
	}

	if (info.runCount) {
		info.runCount--;
		if (info.runCount) {
			info.count++;
		} else {
			info.lastTime = time() - info.currentStart;
			info.totalTime += info.lastTime;
			info.count++;
			info.currentStart = 0;
		}
	} else {
		throw new Error(`Timer ${name} paused more times than started.`);
	}

	return info;
}

export function timer(name: string): TimerInfo {
	return timers[name];
}

export function print(name: string): TimerInfo {
	const info = timers[name];
	if (!info) {
		throw new Error(`No timer started: ${name}`);
	}

	console.log(`---- [${name}] STOP total: ${info.totalTime} count:${info.count}`);

	return info;

View on GitHub (pinned to 6800aefa65)

Solutions

  1. Ensure every stop(name) has a matching start(name) before it
  2. Check that countersProfileFunctionFactory-wrapped functions are not invoked re-entrantly
  3. Guard the stop call behind a flag or call timer(name) and inspect info.count first
  4. Reset profiling state between runs so stale timers are cleared

Example fix

// before
stop('myTimer'); // called in two branches but started once
// after
const info = timer('myTimer');
if (info.count > 0) stop('myTimer');
Defensive patterns

Strategy: validation

Validate before calling

const info = timer('myTimer');
if (info.count === 0) throw new Error('Timer never started');

Type guard

function isStarted(name: string): boolean {
  const t = (<any>global).__nsTimers?.[name];
  return !!t && t.count > 0;
}

Try / catch

try {
  stop('myTimer');
} catch (e) {
  if (!/paused more times than started/.test(e.message)) throw e;
  // treat as already-stopped
}

Prevention

When it happens

Trigger: Calling stop(name) (via countersProfileFunctionFactory-wrapped functions) more times than start(name) was called for the same timer name, e.g. wrapping a function whose factory calls stop twice, or stopping a timer whose start threw.

Common situations: Instrumenting a code path where an early return or exception bypasses one start but a finally block still stops; copy-pasted stop() calls; wrapping recursive functions so stop fires per recursion level more than start.

Related errors


AI-assisted analysis of NativeScript/NativeScript@6800aefa65 (2026-08-30). Data as JSON: /api/errors/862dbb2e9b4fbb39. Report an issue: GitHub.