{"record":{"id":"a7fa21addcbb3f7c","repo":"windmill-labs/windmill","slug":"state-path-not-set","errorCode":null,"errorMessage":"State path not set","messagePattern":"State path not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/windmill-runtime-nativets/src/windmill-client.js","lineNumber":10012,"sourceCode":"    endpoint = `/w/${getWorkspace()}/jobs/run/h/${hash_}`;\n  } else {\n    throw new Error(\"path or hash_ must be provided\");\n  }\n  let url = new URL(OpenAPI.BASE + endpoint);\n  url.search = new URLSearchParams(params).toString();\n  return fetch(url, {\n    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n      Authorization: `Bearer ${OpenAPI.TOKEN}`,\n    },\n    body: JSON.stringify(args),\n  }).then((res) => res.text());\n}\nfunction getStatePath() {\n  const state_path = getEnv(\"WM_STATE_PATH_NEW\") ?? getEnv(\"WM_STATE_PATH\");\n  if (state_path === void 0) {\n    throw Error(\"State path not set\");\n  }\n  return state_path;\n}\nasync function setResource(value, path, initializeToTypeIfNotExist) {\n  !clientSet && setClient();\n  path = path ?? getStatePath();\n  const workspace = getWorkspace();\n  if (await ResourceService.existsResource({ workspace, path })) {\n    await ResourceService.updateResourceValue({\n      workspace,\n      path,\n      requestBody: { value },\n    });\n  } else if (initializeToTypeIfNotExist) {\n    await ResourceService.createResource({\n      workspace,\n      requestBody: { path, value, resource_type: initializeToTypeIfNotExist },\n    });","sourceCodeStart":9994,"sourceCodeEnd":10030,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-runtime-nativets/src/windmill-client.js#L9994-L10030","documentation":"getStatePath reads the run's state path from WM_STATE_PATH_NEW (or legacy WM_STATE_PATH). These are set by the Windmill worker when the run has state persistence configured. If neither variable is defined the function throws this Error, blocking state get/set operations.","triggerScenarios":"Calling getStatePath() directly, or any function defaulting path to getStatePath() (setResource/setState/getState) outside a run with a state path — e.g. outside Windmill, or in a run type that doesn't assign state (plain script without flow state), or env vars removed by the runner.","commonSituations":"Using setState()/getState() in a standalone script rather than inside a flow with state persistence; running locally without WM_STATE_PATH; older Windmill versions that only set WM_STATE_PATH which has since been deprecated/renamed; tests executing the client directly.","solutions":["Use state functions inside a flow with state persistence enabled so the worker sets WM_STATE_PATH","Pass an explicit path argument instead of relying on the state-path default (setResource(value, path, ...))","Set WM_STATE_PATH manually in local/test environments to a valid resource path","Upgrade the worker/runtime so WM_STATE_PATH_NEW is injected correctly"],"exampleFix":"// before\nawait setState({ count: 1 }); // requires WM_STATE_PATH\n// after\nawait setResource({ count: 1 }, 'u/admin/my_state', 'state'); // explicit path","handlingStrategy":"validation","validationCode":"if (process.env.WM_STATE_PATH_NEW === undefined && process.env.WM_STATE_PATH === undefined) {\n  throw new Error('state persistence unavailable: WM_STATE_PATH not set');\n}","typeGuard":"function hasStatePath(env) { return typeof (env.WM_STATE_PATH_NEW ?? env.WM_STATE_PATH) === 'string'; }","tryCatchPattern":"try {\n  await setState(state);\n} catch (e) {\n  if (e.message === 'State path not set') await setResource(state, fallbackPath, 'state');\n  else throw e;\n}","preventionTips":["Use state helpers only inside flows with state persistence enabled","Provide explicit paths instead of relying on the env-var default in portable code","Set WM_STATE_PATH in local test harnesses mirroring the worker env","Keep worker/runtime versions in sync with client expectations (WM_STATE_PATH_NEW)"],"tags":["windmill","environment-variable","missing-env-var","state"],"backgroundTag":"missing-env-var","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}