avajs/ava · error · Error

Options have already been set

Error message

Options have already been set

What it means

AVA worker options are set exactly once per test process via set(). Calling set() again after options were already assigned throws this Error, protecting the process configuration from being overwritten mid-run.

Source

Thrown at lib/worker/options.js:12

let options = null;
export function get() {
	if (!options) {
		throw new Error('Options have not yet been set');
	}

	return options;
}

export function set(newOptions) {
	if (options) {
		throw new Error('Options have already been set');
	}

	options = newOptions;
}

View on GitHub (pinned to bbfd946322)

Solutions

  1. Call set() only once per process; guard initialization with a module-level flag or check.
  2. If options genuinely change, replace set() semantics in a fork rather than calling it again, or extend the options object before the first set().
  3. Audit for duplicate bootstrap paths (double imports, both a shim and the CLI calling set()).

Example fix

// before
set(opts);
set(updatedOpts); // throws

// after
set(opts);
// mutate through your own config instead:
myConfig.override(updatedOpts); // then read via get() + myConfig
Defensive patterns

Strategy: validation

Validate before calling

import {get, set} from './worker/options.js';
function setOnce(newOptions) {
  try { get(); } catch { set(newOptions); return; } // only set when unset
  throw new Error('Options already set');
}

Try / catch

try {
  set(opts);
} catch (err) {
  if (err.message === 'Options have already been set') {
    // bootstrap already ran; treat as idempotent no-op
  } else throw err;
}

Prevention

When it happens

Trigger: Calling set() twice in one worker process; two bootstrap paths both calling set() (e.g. a shim plus the real CLI bootstrap); re-importing/re-initializing the worker environment in the same process (worker reuse across files in the same process, or forked bootstrap executing twice).

Common situations: Custom test harness or integration code that boots AVA workers and invokes set() more than once; hot-reload/watch mode re-running bootstrap in a shared process; accidental double import executing an initialization side effect twice.

Related errors


AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02). Data as JSON: /api/errors/affb018c176a0c6e. Report an issue: GitHub.