{"record":{"id":"affb018c176a0c6e","repo":"avajs/ava","slug":"options-have-already-been-set","errorCode":null,"errorMessage":"Options have already been set","messagePattern":"Options have already been set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/worker/options.js","lineNumber":12,"sourceCode":"let options = null;\nexport function get() {\n\tif (!options) {\n\t\tthrow new Error('Options have not yet been set');\n\t}\n\n\treturn options;\n}\n\nexport function set(newOptions) {\n\tif (options) {\n\t\tthrow new Error('Options have already been set');\n\t}\n\n\toptions = newOptions;\n}\n","sourceCodeStart":1,"sourceCodeEnd":17,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/worker/options.js#L1-L17","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Call set() only once per process; guard initialization with a module-level flag or check.","If options genuinely change, replace set() semantics in a fork rather than calling it again, or extend the options object before the first set().","Audit for duplicate bootstrap paths (double imports, both a shim and the CLI calling set())."],"exampleFix":"// before\nset(opts);\nset(updatedOpts); // throws\n\n// after\nset(opts);\n// mutate through your own config instead:\nmyConfig.override(updatedOpts); // then read via get() + myConfig","handlingStrategy":"validation","validationCode":"import {get, set} from './worker/options.js';\nfunction setOnce(newOptions) {\n  try { get(); } catch { set(newOptions); return; } // only set when unset\n  throw new Error('Options already set');\n}","typeGuard":null,"tryCatchPattern":"try {\n  set(opts);\n} catch (err) {\n  if (err.message === 'Options have already been set') {\n    // bootstrap already ran; treat as idempotent no-op\n  } else throw err;\n}","preventionTips":["Call set() exactly once per worker process","Guard bootstrap with a module-level initialized flag","Audit for duplicate bootstrap paths (shims, watchers, double imports)"],"tags":["ava","worker","initialization","double-set"],"backgroundTag":"state-already-initialized","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}