mastra-ai/mastra · error
Factory project is required
Error message
Factory project is required
What it means
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.
Source
Thrown at mastracode/factory-ui/src/hooks/useFactorySlackWorkItems.ts:13
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useApiConfig } from '../api/config';
import { queryKeys } from '../api/keys';
import { updateFactorySlackWorkItems } from '../ui/domains/workspaces/services/github';
export function useSetFactorySlackWorkItemsMutation(factoryProjectId: string | undefined) {
const { baseUrl } = useApiConfig();
const queryClient = useQueryClient();
return useMutation({
mutationFn: (enabled: boolean) => {
if (!factoryProjectId) throw new Error('Factory project is required');
return updateFactorySlackWorkItems(baseUrl, factoryProjectId, enabled);
},
onSuccess: project => {
queryClient.setQueryData(queryKeys.factoryProject(factoryProjectId), project);
void queryClient.invalidateQueries({ queryKey: queryKeys.factories() });
},
});
}
View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const { mutate } = useSetFactorySlackWorkItemsMutation(projectId);
<Switch onCheckedChange={v => mutate(v)} />
// after
const { mutate } = useSetFactorySlackWorkItemsMutation(projectId);
<Switch disabled={!projectId} onCheckedChange={v => projectId && mutate(v)} /> Defensive patterns
Strategy: validation
Validate before calling
if (!factoryProjectId) return; // keep toggle disabled
Type guard
const hasFactoryProject = (id: string | undefined): id is string => typeof id === 'string' && id.length > 0;
Try / catch
mutate(enabled, { onError: err => { if ((err as Error).message === 'Factory project is required') revertToggle(); } }); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- Factory project is required
- Factory run requires a board work item
- Work item is required
- Select a repository before starting a Factory run
- No Factory selected
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5245095decbe8aa6.
Report an issue: GitHub.