-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(remix): Add v2 support #8415
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { captureException, withScope } from '@sentry/core'; | ||
import { addExceptionMechanism, isNodeEnv, isString } from '@sentry/utils'; | ||
|
||
import type { ErrorResponse } from '../utils/vendor/types'; | ||
|
||
/** | ||
* Checks whether the given error is an ErrorResponse. | ||
* ErrorResponse is when users throw a response from their loader or action functions. | ||
* This is in fact a server-side error that we capture on the client. | ||
* | ||
* @param error The error to check. | ||
* @returns boolean | ||
*/ | ||
function isErrorResponse(error: unknown): error is ErrorResponse { | ||
return typeof error === 'object' && error !== null && 'status' in error && 'statusText' in error; | ||
} | ||
|
||
/** | ||
* Captures an error that is thrown inside a Remix ErrorBoundary. | ||
* | ||
* @param error The error to capture. | ||
* @returns void | ||
*/ | ||
export function captureRemixErrorBoundaryError(error: unknown): void { | ||
const isClientSideRuntimeError = !isNodeEnv() && error instanceof Error; | ||
const isRemixErrorResponse = isErrorResponse(error); | ||
// Server-side errors apart from `ErrorResponse`s also appear here without their stacktraces. | ||
// So, we only capture: | ||
// 1. `ErrorResponse`s | ||
// 2. Client-side runtime errors here, | ||
// And other server - side errors in `handleError` function where stacktraces are available. | ||
if (isRemixErrorResponse || isClientSideRuntimeError) { | ||
const eventData = isRemixErrorResponse | ||
? { | ||
function: 'ErrorResponse', | ||
...error.data, | ||
} | ||
: { | ||
function: 'ReactError', | ||
}; | ||
|
||
withScope(scope => { | ||
scope.addEventProcessor(event => { | ||
addExceptionMechanism(event, { | ||
type: 'instrument', | ||
handled: true, | ||
data: eventData, | ||
}); | ||
return event; | ||
}); | ||
|
||
if (isRemixErrorResponse) { | ||
if (isString(error.data)) { | ||
captureException(error.data); | ||
} else if (error.statusText) { | ||
captureException(error.statusText); | ||
} else { | ||
captureException(error); | ||
} | ||
} else { | ||
captureException(error); | ||
} | ||
}); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { GLOBAL_OBJ } from '@sentry/utils'; | ||
|
||
import type { FutureConfig, ServerBuild } from './vendor/types'; | ||
|
||
export type EnhancedGlobal = typeof GLOBAL_OBJ & { | ||
__remixContext?: { | ||
future?: FutureConfig; | ||
}; | ||
}; | ||
|
||
/** | ||
* Get the future flags from the Remix browser context | ||
* | ||
* @returns The future flags | ||
*/ | ||
export function getFutureFlagsBrowser(): FutureConfig | undefined { | ||
const window = GLOBAL_OBJ as EnhancedGlobal; | ||
|
||
if (!window.__remixContext) { | ||
return; | ||
} | ||
|
||
return window.__remixContext.future; | ||
} | ||
|
||
/** | ||
* Get the future flags from the Remix server build | ||
* | ||
* @param build The Remix server build | ||
* | ||
* @returns The future flags | ||
*/ | ||
export function getFutureFlagsServer(build: ServerBuild): FutureConfig | undefined { | ||
return build.future; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remix question: The ErrorBoundary is picked up during build I assume, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It covers both build and runtime. Client-side React errors, and runtime server errors also end up here. For server-side runtime errors,
handleError
gives us the stacktraces (ErrorBoundary does not), so this implementation skips capturing for that case.