import { useState } from 'react'
import Markdown from 'react-markdown'
// If these vars are missing, we suspect they are not desctructured in the draft method
const knownVars = [
'sa',
'Path',
'Point',
'Snippet',
'paths',
'points',
'snippets',
'absoluteOptions',
'complete',
'measurements',
'options',
'paperless',
'sa',
'scale',
'context',
'getId',
'hide',
'log',
'macro',
'setHidden',
'store',
'unhide',
'units',
'utils',
'Bezier',
'part',
]
// Make it easy to suppress escapint in i18next
const interpolation = { escapeValue: false }
// Extend this method if you want to handle other things than errors
export const analyzeDraftLogLine = ({ type, line, t }) => {
if (type === 'error' && line.stack) return
return null
}
// Helper component to toggle the stack trace
const ShowStackButton = ({ setDetails, details, t, txt = 'clickHereForStackTrace' }) => (
)
// This explains how the error is likely do to restructuring
const NotDestructured = ({ missing, setDetails, details, t }) => (
)
// Component that displays an error log line
const DraftError = ({ err, t }) => {
const [details, setDetails] = useState(false)
const data = []
const stack = err.stack.split('\n')
// Leave this here, it's intentional. We log the error to you can inpect it.
console.log(err)
if (err.name === 'ReferenceError') {
if (err.message.includes('is not defined')) {
const missing = err.message.split(' ').shift()
if (stack[0].includes('/designs/')) {
data.push()
if (knownVars.includes(missing))
data.push()
} else data.push()
}
}
return (
<>
{data}
{t('alsoLogged')}
{details ? (
<>