-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add retry method to share link dialog in case of error #4276
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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
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 |
---|---|---|
|
@@ -7,32 +7,62 @@ import { | |
Typography, | ||
} from '@mui/material' | ||
|
||
import { RawSourceMap, SourceMapConsumer } from 'source-map-js' | ||
import { SourceMapConsumer } from 'source-map-js' | ||
import copy from 'copy-to-clipboard' | ||
|
||
// locals | ||
import Dialog from './Dialog' | ||
import LoadingEllipses from './LoadingEllipses' | ||
|
||
function Link2({ | ||
href, | ||
children, | ||
}: { | ||
href: string | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<Link target="_blank" href={href}> | ||
{children} | ||
</Link> | ||
) | ||
} | ||
|
||
async function myfetch(uri: string) { | ||
const res = await fetch(uri) | ||
if (!res.ok) { | ||
throw new Error(`HTTP ${res.status} fetching ${uri}: ${await res.text()}`) | ||
} | ||
return res | ||
} | ||
|
||
async function myfetchjson(uri: string) { | ||
const res = await myfetch(uri) | ||
return res.json() | ||
} | ||
|
||
async function myfetchtext(uri: string) { | ||
const res = await myfetch(uri) | ||
return res.text() | ||
} | ||
|
||
// produce a source-map resolved stack trace | ||
// reference code https://stackoverflow.com/a/77158517/2129219 | ||
const sourceMaps: Record<string, RawSourceMap> = {} | ||
const sourceMaps: Record<string, SourceMapConsumer> = {} | ||
async function getSourceMapFromUri(uri: string) { | ||
if (sourceMaps[uri] != undefined) { | ||
return sourceMaps[uri] | ||
} | ||
const uriQuery = new URL(uri).search | ||
const currentScriptContent = await (await fetch(uri)).text() | ||
const currentScriptContent = await myfetchtext(uri) | ||
|
||
let mapUri = | ||
new RegExp(/\/\/# sourceMappingURL=(.*)/).exec(currentScriptContent)?.[1] || | ||
'' | ||
mapUri = new URL(mapUri, uri).href + uriQuery | ||
|
||
const map = await (await fetch(mapUri)).json() | ||
|
||
const map = new SourceMapConsumer(await myfetchjson(mapUri)) | ||
sourceMaps[uri] = map | ||
|
||
return map | ||
} | ||
|
||
|
@@ -48,7 +78,7 @@ async function mapStackTrace(stack: string) { | |
} | ||
|
||
const uri = match[2] | ||
const consumer = new SourceMapConsumer(await getSourceMapFromUri(uri)) | ||
const consumer = await getSourceMapFromUri(uri) | ||
|
||
const originalPosition = consumer.originalPositionFor({ | ||
line: parseInt(match[3]), | ||
|
@@ -100,14 +130,8 @@ function Contents({ text }: { text: string }) { | |
return ( | ||
<> | ||
<Typography> | ||
Post a new issue at{' '} | ||
<Link href={githubLink} target="_blank"> | ||
GitHub | ||
</Link>{' '} | ||
or send an email to{' '} | ||
<Link href={emailLink} target="_blank"> | ||
[email protected] | ||
</Link>{' '} | ||
Post a new issue at <Link2 href={githubLink}>GitHub</Link2> or send an | ||
email to <Link2 href={emailLink}>[email protected]</Link2>{' '} | ||
</Typography> | ||
<pre | ||
style={{ | ||
|
@@ -129,12 +153,12 @@ export default function ErrorMessageStackTraceDialog({ | |
onClose, | ||
}: { | ||
onClose: () => void | ||
error: Error | ||
error: unknown | ||
}) { | ||
const [mappedStackTrace, setMappedStackTrace] = useState<string>() | ||
const [secondaryError, setSecondaryError] = useState<unknown>() | ||
const [clicked, setClicked] = useState(false) | ||
const stackTracePreProcessed = `${error.stack}` | ||
const stackTracePreProcessed = `${typeof error === 'object' && error !== null && 'stack' in error ? error.stack : ''}` | ||
const errorText = `${error}` | ||
const stackTrace = stripMessage(stackTracePreProcessed, errorText) | ||
|
||
|
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.
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.
this is a bonus optimization. if the stack trace goes through 20 stack frames of mobx-state-tree function calls, then it was reparsing the stack trace 20 times which added up to 5 seconds of waiting for the stack trace. this parses it just once