1
0
Fork 0

fix(shared): Ensure that error name and message info is included in error log

This commit is contained in:
Benjamin F 2022-12-29 08:49:47 -08:00
parent 99ca06dba6
commit 49c05bd419

View file

@ -2,21 +2,29 @@ import Markdown from 'react-markdown'
import { formatMm } from 'shared/utils'
import { Tab, Tabs } from '../mdx/tabs.js'
export const Error = ({ err }) => (
<pre>
{err.stack
.split(/\n/g)
.slice(0, 5)
.map((l, i) => (
<code
key={`error-${i}`}
className={'block whitespace-pre-wrap' + (i > 0 ? ' break-all' : '')}
>
{l}
</code>
))}
</pre>
)
export const Error = ({ err }) => {
// Include the error name and message info if it isn't already at the top
// of the error stack.
let stack = err.stack
if (!err.stack.startsWith(err.toString())) {
stack = err.toString() + '\n' + err.stack
}
return (
<pre>
{stack
.split(/\n/g)
.slice(0, 5)
.map((l, i) => (
<code
key={`error-${i}`}
className={'block whitespace-pre-wrap' + (i > 0 ? ' break-all' : '')}
>
{l}
</code>
))}
</pre>
)
}
// Markdown wrapper to suppress creation of P tags
const Md = ({ children }) => (