twentyhq/twenty · error · Error
Failed to create view
Error message
Failed to create view
What it means
Thrown in useCreateViewFromCurrentView after performViewAPICreate returned a non-failed status, but `result.response.data.createView.id` is null/undefined. It is a defensive guard for the case where the persist layer reported success yet the created view id is missing from the response.
Source
Thrown at packages/twenty-front/src/modules/views/hooks/useCreateViewFromCurrentView.ts:162
: undefined,
calendarEndFieldMetadataId:
viewType === ViewType.CALENDAR
? calendarEndFieldMetadataId
: undefined,
visibility,
},
},
objectMetadataItem.id,
);
if (result.status === 'failed') {
return undefined;
}
const newViewId = result.response.data?.createView.id;
if (isUndefinedOrNull(newViewId)) {
throw new Error('Failed to create view');
}
const fieldResult = await performViewFieldAPICreate({
inputs: sourceView.viewFields.map((viewField) => ({
id: v4(),
fieldMetadataId: viewField.fieldMetadataId,
position: viewField.position,
isVisible: viewField.isVisible,
size: viewField.size,
aggregateOperation: viewField.aggregateOperation,
viewFieldGroupId: viewField.viewFieldGroupId,
viewId: newViewId,
})),
});
if (fieldResult.status === 'failed') {
return undefined;
}View on GitHub (pinned to 1f5dd2bbd2)
Solutions
- Inspect result.response.data shape and the errors array for the createView mutation.
- Re-run graphql codegen to ensure id is selected on CreateView.
- Have performViewAPICreate propagate a failed status when createView is null instead of relying on this downstream guard.
Example fix
// before: if (isUndefinedOrNull(newViewId)) { throw new Error('Failed to create view'); }
// after: if (isUndefinedOrNull(newViewId)) {
// throw new Error(result.response.errors?.[0]?.message ?? 'Failed to create view');
// } Defensive patterns
Strategy: try-catch
Validate before calling
const hasCreatedViewId = (r: MetadataRequestResult<any>): boolean => r.status === 'successful' && isDefined(r.response?.data?.createView?.id);
Type guard
const isCreateViewId = (v: unknown): v is string => typeof v === 'string' && v.length > 0;
Try / catch
try {
await createViewFromCurrentView({...}, true);
} catch (e) {
showError((e as Error).message); // 'Failed to create view'
} Prevention
- Make performViewAPICreate return a failed status when createView is null so the downstream guard is unreachable.
- Re-run metadata graphql:generate after CreateView selection-set changes.
- Surface mutation errors to the user instead of relying on a generic throw.
When it happens
Trigger: performViewAPICreate resolves with status 'successful' but the inner mutation data is absent or createView has no id. Race between optimistic update and server response. Codegen drift on the CreateView selection set omitting id.
Common situations: Mutation resolved with errors but the persist operation still classified the result as successful. Schema change removed id from the createView payload.
Related errors
- Failed to create view
- Failed to create view filter group
- GraphQL errors: ${json.errors.map((e) => e.message).join(';
- No getAuthTokensFromSSOExchangeToken result
- Field ${fieldMetadata.name} is missing, please refresh the p
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/248c02f00c55ab87.
Report an issue: GitHub.