{"record":{"id":"eb0c8df183a959fd","repo":"avajs/ava","slug":"options-have-not-yet-been-set","errorCode":null,"errorMessage":"Options have not yet been set","messagePattern":"Options have not yet been set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/worker/options.js","lineNumber":4,"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 (test file path, config, etc.) are injected by the AVA CLI at startup via set(). get() throws this Error when called before options were ever set — i.e. code that depends on the worker options module is running outside an AVA-managed test process, or runs before AVA's bootstrap.","triggerScenarios":"Importing/using lib/worker/options.js get() from a module loaded at top level before AVA initializes the worker; running code that depends on AVA internals outside the AVA CLI; an internal module reading options during module import instead of lazily at test time.","commonSituations":"Running a test-support module directly with node; importing worker-internal modules from user code; circular imports causing options.js to be consulted before the CLI's bootstrap ran.","solutions":["Ensure the code runs inside an AVA test process launched by the AVA CLI.","Defer option access until test execution time (not at module import) so set() has already run.","If building tooling around AVA, pass configuration explicitly instead of relying on worker options."],"exampleFix":"// before\nimport {get} from './worker/options.js';\nconst opts = get(); // module top-level, options not set yet\n\n// after\nimport {get} from './worker/options.js';\nexport function computeSomething() {\n  const opts = get(); // called during test run\n  ...\n}","handlingStrategy":"try-catch","validationCode":"import {get} from './worker/options.js';\nfunction safeGet() {\n  try { return get(); } catch { return null; } // null means not running under AVA yet\n}","typeGuard":null,"tryCatchPattern":"let opts;\ntry {\n  opts = get();\n} catch (err) {\n  if (err.message === 'Options have not yet been set') {\n    opts = defaultOptions; // or defer until after AVA bootstrap\n  } else throw err;\n}","preventionTips":["Access options lazily during test execution, not at module import time","Only run code depending on worker options inside AVA test processes","Avoid circular imports that reach options.js before bootstrap"],"tags":["ava","worker","initialization","missing-state"],"backgroundTag":"resource-not-ready","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}