Loading
Guard snippet view against empty and errored GraphQL responses
What does this MR do and why?
Fixes a production Sentry error (TypeError: Cannot read properties of undefined (reading 'updateSnippet')). There are two distinct crash paths.
GetSnippetQuerycan succeed but return an emptynodesarray — likely an authorization edge case where GraphQL reports success but yields no snippet. The snippets mixin was settingsnippetto{}in that case, andsnippet_header.vuethen readsnippet.userPermissions.updateSnippetfrom it unconditionally, throwing.- vue-apollo v3 calls a smart query's
update()hook withundefineddata on errored responses unlesserrorPolicyis explicitly'none'. All three snippet queries were reading into the payload unguarded, so a network or GraphQL error would also throw.
The fix addresses both paths.
- For the empty-response case, optional chaining guards the permission reads in the snippet header, and the snippet show page renders a danger alert ("Could not load the snippet. Refresh the page and try again.") instead of mounting the snippet components when no snippet is returned.
- For the error case, explicit
errorPolicy: ERROR_POLICY_NONEis added to the three snippet queries, with anerror()hook in the mixin that sets an error flag and reports to Sentry.
This mirrors the patterns established by !254565 (merged) and https://gitlab.com/gitlab-org/gitlab/-/work_items/625054 (blob_content_viewer) as part of the Sentry Signal Loop epic.
References
- Work item: https://gitlab.com/gitlab-org/gitlab/-/work_items/632204
- Sentry Signal Loop epic: gitlab-org#23441
- Pattern reference (snippet header guards): !254565 (merged)
- Pattern reference (errorPolicy + error hook): https://gitlab.com/gitlab-org/gitlab/-/work_items/625054
Screenshots or screen recordings
Taken on a local instance with GetSnippetQuery stubbed to return empty nodes (the production failure mode) — before = master, after = this branch.
How to set up and validate locally
- Visit any snippet page (personal or project) — it should render normally as a regression check.
- To trigger the new error state: open DevTools → Network, enable request blocking for
/api/graphql, then reload the snippet page. The page should display the danger alert instead of crashing or spinning indefinitely.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Chaoyue Zhao

