{"record":{"id":"9925e29ee89073fb","repo":"mastra-ai/mastra","slug":"failed-to-load-factories","errorCode":null,"errorMessage":"Failed to load Factories","messagePattern":"Failed to load Factories","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory-ui/src/hooks/useFactories.ts","lineNumber":25,"sourceCode":"  createFactoryProject,\n  deleteFactoryProject,\n  linkRepository,\n  listFactoryProjects,\n  unlinkRepository,\n} from '../ui/domains/workspaces/services/github';\nimport type { FactoryProject, GithubRepo } from '../ui/domains/workspaces/services/github';\n\nfunction invalidateFactories(queryClient: ReturnType<typeof useQueryClient>) {\n  void queryClient.invalidateQueries({ queryKey: queryKeys.factories() });\n}\n\nfunction refetchFactories(queryClient: ReturnType<typeof useQueryClient>) {\n  return queryClient.refetchQueries({ queryKey: queryKeys.factories() });\n}\n\nasync function fetchFactoryProjects(baseUrl: string): Promise<FactoryProject[]> {\n  const projects = await listFactoryProjects(baseUrl);\n  if (!projects) throw new Error('Failed to load Factories');\n  return projects;\n}\n\nexport function useFactoriesQuery() {\n  const { baseUrl } = useApiConfig();\n  return useQuery({\n    queryKey: queryKeys.factories(),\n    queryFn: () => fetchFactoryProjects(baseUrl),\n  });\n}\n\nexport function useFactoryQuery(factoryId: string | undefined) {\n  const { baseUrl } = useApiConfig();\n  return useQuery({\n    queryKey: queryKeys.factories(),\n    queryFn: () => fetchFactoryProjects(baseUrl),\n    select: (factories: FactoryProject[]) => factories.find(factory => factory.id === factoryId),\n    enabled: Boolean(factoryId),","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory-ui/src/hooks/useFactories.ts#L7-L43","documentation":"`fetchFactoryProjects` wraps `listFactoryProjects`, which returns null instead of throwing on request failure. This error converts that null into an explicit failure so React Query treats it as an error rather than caching an empty result.","triggerScenarios":"`listFactoryProjects(baseUrl)` returns null/undefined — typically when the underlying fetch to the Factories listing endpoint fails or the payload shape is unexpected.","commonSituations":"Factory server unreachable or returning non-JSON; user lacks permission to list factory projects; baseUrl misconfigured; response schema changed between UI and server versions so the list parse fails and null is returned.","solutions":["Check network/server health for the Factories listing endpoint and confirm the server is running","Verify baseUrl and that the authenticated user has access to factory projects","Confirm UI and server versions are compatible (response schema for the projects list)","Add logging inside listFactoryProjects to see why it returns null instead of a list"],"exampleFix":"// caller-side\nconst { data, isError, error } = useFactoriesQuery();\nif (isError) {\n  showEmptyState('Factories unavailable', error.message); // \"Failed to load Factories\"\n  // offer a retry button calling queryClient.refetchQueries({queryKey: queryKeys.factories()})\n}","handlingStrategy":"retry","validationCode":"// pre-flight: server reachable and response shaped as a project list\nconst res = await fetch(`${baseUrl}/factories`, { credentials: 'include' });\nif (!res.ok) throw new Error(`Factories endpoint unavailable (${res.status})`);\nconst body = await res.json();\nif (!Array.isArray(body?.projects)) throw new Error('Unexpected Factories payload; check server version');","typeGuard":"function isFactoryProjectList(value: unknown): value is FactoryProject[] {\n  return Array.isArray(value) && value.every(p => typeof p === 'object' && p !== null && 'id' in p);\n}","tryCatchPattern":"const { data, isError, refetch } = useFactoriesQuery();\nif (isError) {\n  showRetryBanner('Failed to load Factories', () => refetch());\n}","preventionTips":["Confirm the Factory server is running and reachable before mounting the Factories page","Keep UI and server response schemas in sync (contract tests on the projects endpoint)","Verify user permissions to list factory projects","Log the underlying reason listFactoryProjects returns null to distinguish network vs schema issues"],"tags":["http","react-query","factory-ui"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}