fix: catch mutateAsync rejection in GcpCallback to prevent unhandled promise errors #SUPERLOG - #452
Open
superlog-app[bot] wants to merge 1 commit into
Open
fix: catch mutateAsync rejection in GcpCallback to prevent unhandled promise errors #SUPERLOG#452superlog-app[bot] wants to merge 1 commit into
superlog-app[bot] wants to merge 1 commit into
Conversation
…promise errors #SUPERLOG Delivery-Id: 1695164479158365e8c9ca7ec82f30f8db670ec8bfe18a519db5fa0649307350 Delivery-Base: main
| try { | ||
| await connect.mutateAsync(selectedProjectId); | ||
| window.location.assign("/connect/gcp?gcp=connected"); | ||
| } catch { |
Contributor
Author
There was a problem hiding this comment.
traces · blocking — Record the error on the active span inside the catch block
Call span.recordException(e) and span.setStatus({ code: SpanStatusCode.ERROR }) (or the repo's equivalent helper) inside the catch so the provisioning failure is visible in traces; without this, swallowing the rejection removes the only browser-side signal that was previously captured by the unhandledrejection listener, leaving operators unable to correlate user-facing GCP connect failures with backend 502s.
Suggested change
| } catch { | |
| } catch (e) { | |
| // connect.error surfaces via the error banner above. | |
| const span = trace.getActiveSpan(); | |
| if (span) { | |
| span.recordException(e as Error); | |
| span.setStatus({ code: SpanStatusCode.ERROR }); | |
| } | |
| } |
Useful? React with 👍 / 👎.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a user selects a Google Cloud project on
/connect/gcpand clicks Connect project, the page callsconnect.mutateAsync(selectedProjectId)inside an asynconClickhandler without a surroundingtry/catch. If GCP provisioning fails (e.g. because Superlog'ssuperlog-infraorg policy blocks adding the Cloud Logging service agent to the Pub/Sub topic IAM policy),mutateAsyncre-throws theApiErrorand — because nothing catches it in the handler — it becomes an unhandled promise rejection. The OTelwindow.unhandledrejectionlistener records it as abrowser.exceptionERROR span, opening a production incident.The user-facing error is already shown via
connect.error(the red banner at line 126), so no UI change is needed; only the unhandled rejection needs to be suppressed.Root cause
React Query's
mutateAsyncre-throws on failure (unlikemutate). The established codebase convention — already applied inGcpConnectFlow.tsx— is to wrapmutateAsyncin a try/catch and let the mutation's.errorstate drive the UI:GcpCallback.tsxwas missing this guard.Fix
Wrapped the
mutateAsynccall inGcpCallback.tsxin an identical try/catch. Thewindow.location.assignonly runs on success;connect.errorcontinues to display the error message when the call fails.Related infrastructure issue
The underlying GCP provisioning failure (502 from
setIamPolicy) is caused by aconstraints/iam.allowedPolicyMemberDomainsorg policy onsuperlog-infrathat rejects Cloud Logging service agents from customer projects. That requires a separate GCP infrastructure fix (allowgcp-sa-logging.iam.gserviceaccount.comin the policy). This PR only addresses the browser-side unhandled rejection.Incident: ee226810-502e-4c6c-ae61-b6888b87c7c4
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Prevent unhandled promise rejections in the GCP connect flow by wrapping
connect.mutateAsyncin a try/catch inGcpCallback. On failure, the existing error banner shows the message; on success we redirect to/connect/gcp?gcp=connected.Written for commit bf207e6. Summary will update on new commits.