Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions components/error-boundary.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component } from 'react'
import { Component, useState } from 'react'
import { StaticLayout } from './layout'
import styles from '@/styles/error.module.css'
import Image from 'react-bootstrap/Image'
import copy from 'clipboard-copy'
import Button from 'react-bootstrap/Button'
import { useToast } from './toast'
import { decodeMinifiedStackTrace } from '@/lib/stacktrace'

class ErrorBoundary extends Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -61,16 +61,25 @@ export default ErrorBoundary
// This button is a functional component so we can use `useToast` hook, which
// can't be easily done in a class component that already consumes a context
const CopyErrorButton = ({ errorDetails }) => {
const [copying, setCopying] = useState(false)
const toaster = useToast()
const onClick = async () => {
setCopying(true)
try {
const { decodeMinifiedStackTrace } = await import('@/lib/stacktrace')
const decodedDetails = await decodeMinifiedStackTrace(errorDetails)
await copy(decodedDetails)
toaster?.success?.('copied')
} catch (err) {
console.error(err)
toaster?.danger?.('failed to copy')
} finally {
setCopying(false)
}
}
return <Button className='mt-3' onClick={onClick}>copy error information</Button>
return (
<Button className='mt-3' onClick={onClick} disabled={copying}>
{copying ? 'copying...' : 'copy error information'}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this is nice to look at, the toaster already does the job of giving visual feedback, so this is unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, removed.

</Button>
)
}