{"record":{"id":"52c01dd812578ba6","repo":"paperclipai/paperclip","slug":"select-a-company-to-create-secrets-52c01d","errorCode":null,"errorMessage":"Select a company to create secrets","messagePattern":"Select a company to create secrets","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ui/src/pages/RoutineDetail.production.tsx","lineNumber":254,"sourceCode":"  });\n  const { data: projects } = useQuery({\n    queryKey: queryKeys.projects.list(selectedCompanyId!, { includeArchived: true }),\n    queryFn: () => projectsApi.list(selectedCompanyId!, { includeArchived: true }),\n    enabled: !!selectedCompanyId,\n  });\n  const { data: companyMembers } = useQuery({\n    queryKey: queryKeys.access.companyUserDirectory(selectedCompanyId!),\n    queryFn: () => accessApi.listUserDirectory(selectedCompanyId!),\n    enabled: !!selectedCompanyId,\n  });\n  const { data: availableSecrets = [] } = useQuery({\n    queryKey: selectedCompanyId ? queryKeys.secrets.list(selectedCompanyId) : [\"secrets\", \"none\"],\n    queryFn: () => secretsApi.list(selectedCompanyId!),\n    enabled: Boolean(selectedCompanyId),\n  });\n  const createSecret = useMutation({\n    mutationFn: (input: { name: string; value: string }) => {\n      if (!selectedCompanyId) throw new Error(\"Select a company to create secrets\");\n      return secretsApi.create(selectedCompanyId, input);\n    },\n    onSuccess: () => {\n      if (!selectedCompanyId) return;\n      queryClient.invalidateQueries({ queryKey: queryKeys.secrets.list(selectedCompanyId) });\n    },\n  });\n\n  const routineDefaults = useMemo<RoutineEditDraft | null>(\n    () =>\n      routine\n        ? {\n            title: routine.title,\n            description: routine.description ?? \"\",\n            projectId: routine.projectId ?? \"\",\n            assigneeAgentId: routine.assigneeAgentId ?? \"\",\n            priority: routine.priority,\n            concurrencyPolicy: routine.concurrencyPolicy,","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/ui/src/pages/RoutineDetail.production.tsx#L236-L272","documentation":"createSecret in RoutineDetail is company-scoped: secrets are created under a specific company via secretsApi.create(companyId, input). If no company is selected (selectedCompanyId is null), the mutation throws this error instead of calling the API. It guards against creating a secret with no owning company.","triggerScenarios":"Calling createSecret.mutate({ name, value }) while no company is selected in the company context — e.g. submitting the create-secret form before the company selector is populated.","commonSituations":"Opening the routine detail page before company selection hydrates; the company selector was never set; a deep link that skips company selection; the form remained enabled while company context was loading.","solutions":["Select a company before submitting the create-secret form.","Disable the form's submit button (or the whole form) when !selectedCompanyId.","Redirect to company selection when this page requires a company and none is chosen.","Ensure the company context provider has finished loading before rendering the secrets panel."],"exampleFix":"// before\nmutationFn: (input) => {\n  if (!selectedCompanyId) throw new Error(\"Select a company to create secrets\");\n  return secretsApi.create(selectedCompanyId, input);\n},\n// after (form-level guard)\n<button type=\"submit\" disabled={!selectedCompanyId || createSecret.isPending}>\n  Create secret\n</button>","handlingStrategy":"validation","validationCode":"if (!selectedCompanyId) {\n  toast.info(\"Select a company to create secrets\");\n  return;\n}","typeGuard":"const canCreateSecret = (id: string | null | undefined): id is string => typeof id === \"string\" && id.length > 0;","tryCatchPattern":"try {\n  await createSecret.mutateAsync({ name, value });\n} catch (e) {\n  if (e.message === \"Select a company to create secrets\") toast.info(e.message);\n  else toast.error(\"Could not create secret\");\n}","preventionTips":["Disable the create-secret form until a company is selected.","Gate the whole secrets panel on company selection context.","Persist/restore the last selected company so scoped pages always have an id."],"tags":["ui","company-scope","secrets","missing-selection"],"backgroundTag":"missing-required-argument","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}