{"record":{"id":"8825341af8f7aa8a","repo":"paperclipai/paperclip","slug":"select-a-company-to-create-environments","errorCode":null,"errorMessage":"Select a company to create environments","messagePattern":"Select a company to create environments","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/src/pages/CompanyEnvironments.tsx","lineNumber":1413,"sourceCode":"    },\n    onError: (error) => {\n      pushToast({\n        title: \"Failed to save environment variables\",\n        body: error instanceof Error ? error.message : \"Environment variables save failed.\",\n        tone: \"error\",\n      });\n    },\n  });\n\n  const environmentMutation = useMutation({\n    mutationFn: async (form: EnvironmentFormState) => {\n      const body = buildEnvironmentPayload(form);\n\n      if (editingEnvironmentId) {\n        return await environmentsApi.update(editingEnvironmentId, body, selectedCompanyId);\n      }\n\n      if (!selectedCompanyId) throw new Error(\"Select a company to create environments\");\n      return await environmentsApi.create(selectedCompanyId!, body);\n    },\n    onSuccess: async (environment) => {\n      const wasEditing = editingEnvironmentId !== null;\n      if (selectedCompanyId) {\n        await queryClient.invalidateQueries({\n          queryKey: queryKeys.environments.list(selectedCompanyId),\n        });\n      }\n      await queryClient.invalidateQueries({\n        queryKey: queryKeys.environments.customImageTemplate(environment.id),\n      });\n      initializedFormKeyRef.current = null;\n      setEnvironmentForm(createEmptyEnvironmentForm());\n      setEnvironmentFormBaselineKey(null);\n      setEnvironmentVariablesDirty(false);\n      environmentMutation.reset();\n      draftEnvironmentProbeMutation.reset();","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/ui/src/pages/CompanyEnvironments.tsx#L1395-L1431","documentation":"Guard in the environmentMutation mutationFn (create branch): creating an environment requires a selectedCompanyId, and the company selector context is empty, so the create path aborts client-side before calling environmentsApi.create.","triggerScenarios":"Thrown at ui/src/pages/CompanyEnvironments.tsx:1385 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Select a company from the company picker before creating environments."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}