{"record":{"id":"5245095decbe8aa6","repo":"mastra-ai/mastra","slug":"factory-project-is-required-524509","errorCode":null,"errorMessage":"Factory project is required","messagePattern":"Factory project is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory-ui/src/hooks/useFactorySlackWorkItems.ts","lineNumber":13,"sourceCode":"import { useMutation, useQueryClient } from '@tanstack/react-query';\n\nimport { useApiConfig } from '../api/config';\nimport { queryKeys } from '../api/keys';\nimport { updateFactorySlackWorkItems } from '../ui/domains/workspaces/services/github';\n\nexport function useSetFactorySlackWorkItemsMutation(factoryProjectId: string | undefined) {\n  const { baseUrl } = useApiConfig();\n  const queryClient = useQueryClient();\n\n  return useMutation({\n    mutationFn: (enabled: boolean) => {\n      if (!factoryProjectId) throw new Error('Factory project is required');\n      return updateFactorySlackWorkItems(baseUrl, factoryProjectId, enabled);\n    },\n    onSuccess: project => {\n      queryClient.setQueryData(queryKeys.factoryProject(factoryProjectId), project);\n      void queryClient.invalidateQueries({ queryKey: queryKeys.factories() });\n    },\n  });\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory-ui/src/hooks/useFactorySlackWorkItems.ts#L1-L22","documentation":"useSetFactorySlackWorkItemsMutation toggles the Slack work-items setting for a factory via updateFactorySlackWorkItems(baseUrl, factoryProjectId, enabled). The factoryProjectId parameter is optional-typed (`string | undefined`), so the mutationFn throws 'Factory project is required' if it is undefined. On success it also writes the returned project into the query cache, so it must never run without a valid id.","triggerScenarios":"Calling slackWorkItemsMutation.mutate(true|false) while factoryProjectId is undefined — usually the toggle switch rendered before the factory project query resolved, or the id came from an optional route/selection param.","commonSituations":"Settings panel mounted optimistically while the factory list query is still loading; toggling the Slack switch on a page whose project id failed to parse from the URL; passing project?.id instead of a guaranteed id.","solutions":["Disable the Slack work-items toggle until factoryProjectId is available.","Confirm the factory project query has succeeded before rendering the settings section that owns this mutation.","Check that the correct id (factoryProjectId, not another project identifier) is passed to the hook."],"exampleFix":"// before\nconst { mutate } = useSetFactorySlackWorkItemsMutation(projectId);\n<Switch onCheckedChange={v => mutate(v)} />\n\n// after\nconst { mutate } = useSetFactorySlackWorkItemsMutation(projectId);\n<Switch disabled={!projectId} onCheckedChange={v => projectId && mutate(v)} />","handlingStrategy":"validation","validationCode":"if (!factoryProjectId) return; // keep toggle disabled","typeGuard":"const hasFactoryProject = (id: string | undefined): id is string => typeof id === 'string' && id.length > 0;","tryCatchPattern":"mutate(enabled, { onError: err => { if ((err as Error).message === 'Factory project is required') revertToggle(); } });","preventionTips":["Disable the Slack work-items toggle until the project id is available.","Load settings panels under a Suspense/loading boundary tied to the project query.","Revert optimistic toggle state in onError."],"tags":["react-query","guard-clause","missing-parameter","factory-ui"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}