{"record":{"id":"7fb9496ec4d91eca","repo":"different-ai/openwork","slug":"app-unknown-error","errorCode":"app.unknown_error","errorMessage":"t(\"app.unknown_error\")","messagePattern":"t\\(\"app\\.unknown_error\"\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/settings/pages/environment-variable-provider.tsx","lineNumber":140,"sourceCode":"    },\n    onError: (error) => {\n      toast.error(error.message);\n    },\n  });\n\n  const markChangesPending = useCallback(() => {\n    clearOpenworkEnvSystemContextCache();\n    queryClient.setQueryData([\"settings\", \"environment\", \"pending-changes\", runtimeKey], true);\n    resetApply();\n    client?.setUserEnvPendingChanges(true, runtimeKey).catch(() => undefined);\n\n    toast.info(t(\"settings.environment.restart_required\"));\n  }, [client, resetApply, queryClient, runtimeKey]);\n\n  const { mutate: modifyAsync, isPending: isModifying, reset: resetModify, error: modifyError } = useMutation({\n    mutationFn: async (nextEditor: EnvironmentEditorDraft) => {\n      if (!client) {\n        throw new Error(t(\"app.unknown_error\"));\n      }\n\n      const keyError = validateKey(nextEditor.key);\n\n      if (keyError) {\n        throw new Error(keyError);\n      }\n\n      const key = nextEditor.key.trim();\n      const existingItems = queryClient.getQueryData<{ items: EnvironmentVariableItem[] }>(\n        environmentUserEnvQueryKey(runtimeKey),\n      )?.items;\n\n      if (nextEditor.mode === \"add\" && existingItems?.some((item) => item.key === key)) {\n        throw new Error(t(\"settings.environment.validation_duplicate\"));\n      }\n\n      return client.upsertUserEnv([{ key, value: nextEditor.value }]);","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/settings/pages/environment-variable-provider.tsx#L122-L158","documentation":"In EnvironmentVariableProvider the modify-env mutation requires an initialized OpenWork client. If the client object is null (the app runtime/connection has not been established), the mutation throws an error with the localized \"app.unknown_error\" message rather than making a call on a null object.","triggerScenarios":"Submitting the environment variable editor (upsert) before the client is available — e.g. during app startup, after a server disconnect, or on a runtime where client injection failed.","commonSituations":"User edits env vars while the backend/server connection is down; race between app boot and user interaction; remote workspace where the client never initialized.","solutions":["Reconnect to the server / restart the app so the client initializes, then retry","Wait for the client/connection to be ready before enabling the save action","Check app logs for why client initialization failed"],"exampleFix":"// before\nmodifyAsync(draft); // client may be null\n// after\nif (!client) return;\nmodifyAsync(draft);","handlingStrategy":"type-guard","validationCode":"if (!client) {\n  showReconnectToast();\n  return;\n}\nmodifyAsync(draft);","typeGuard":"const hasClient = (c: Client | null | undefined): c is Client => c != null;","tryCatchPattern":"try {\n  modifyAsync(draft);\n} catch (e) {\n  if ((e as Error).message.includes(\"unknown_error\")) promptReconnect();\n  else throw e;\n}","preventionTips":["Check client availability before rendering or enabling editor actions","Gate mutations behind a connection-ready state","Subscribe to connection status to reset the form on disconnect"],"tags":["null-client","environment-variables","react-query"],"backgroundTag":"null-client-uninitialized","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}