Skip to content

Commit

Permalink
jscad-web: show error name
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Sep 20, 2023
1 parent 82a6da5 commit 3b54017
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
16 changes: 10 additions & 6 deletions apps/jscad-web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const viewState = new ViewState()
const gizmo = (window.gizmo = new Gizmo())
byId('overlay').parentNode.appendChild(gizmo)

let projectName = 'jscad'
let model = []

// load default model unless another model was already loaded
Expand Down Expand Up @@ -101,9 +102,10 @@ const setError = error => {
const errorBar = byId('error-bar')
if (error) {
console.error(error)
const message = formatStacktrace(error).replace(/^Error: /, '')
const errorMessage = byId('error-message')
errorMessage.innerText = message
const name = (error.name || 'Error') + ': '
byId('error-name').innerText = name
const message = formatStacktrace(error)
byId('error-message').innerText = message
errorBar.classList.add('visible')
} else {
errorBar.classList.remove('visible')
Expand Down Expand Up @@ -139,15 +141,19 @@ const handlers = {
const { sendCmd, sendNotify } = initMessaging(worker, handlers)

const spinner = byId('spinner')
let jobs = 0
async function sendCmdAndSpin(method, params) {
jobs++
spinner.style.display = 'block'
try {
return await sendCmd(method, params)
} catch (error) {
setError(error)
throw error
} finally {
spinner.style.display = 'none'
if (--jobs === 0) {
spinner.style.display = 'none'
}
}
}

Expand All @@ -173,8 +179,6 @@ const runScript = async ({ script, url = './index.js', base, root }) => {
genParams({ target: byId('paramsDiv'), params: result.def || {}, callback: paramChangeCallback })
}

let projectName = 'jscad'

const loadExample = source => {
editor.setSource(source)
runScript({ script: source })
Expand Down
2 changes: 1 addition & 1 deletion apps/jscad-web/src/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export const formatStacktrace = (error) => {
.map((line) => line.replace(/@http.*?bundle.worker.js.* > eval:/, ' ')) // firefox
.map((line) => line.replace(/^\s*(at )?/, ' at ')) // indent

return [error.toString(), ...cleaned].join('\n')
return [error.message, ...cleaned].join('\n')
}
2 changes: 1 addition & 1 deletion apps/jscad-web/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>JSCAD</h1>
</div>

<div id="error-bar">
<label>Error:</label>
<label id="error-name">Error:</label>
<span id="error-message"></span>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion packages/fs-provider/fs-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ const getWorkspaceAliases = async (sw) => {
alias.push({ name, path: `/${w}/${main}` })
}
} catch (error) {
throw new Error(`failed to parse package.json\n ${error}`)
error.message = `failed to parse package.json\n ${error}`
throw error
}
}
return alias
Expand Down
4 changes: 2 additions & 2 deletions packages/require/src/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ const requireModule = (id, url, source, _require) => {
runModule(_require, exports, module, source)
return module
} catch (err) {
console.error('error loading module ' + url, err)
throw new Error(`failed loading module ${id}\n ${err}`)
err.message = `failed loading module ${id}\n ${err}`
throw err
}
}

Expand Down

0 comments on commit 3b54017

Please sign in to comment.