Skip to content

Commit

Permalink
fix: Improve exception formatting (#1052)
Browse files Browse the repository at this point in the history
* fix: Improve exception formatting

* fix: Serialize full error data between contexts
  • Loading branch information
obany authored Apr 29, 2021
1 parent d8069c7 commit 700c752
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
9 changes: 8 additions & 1 deletion packages/desktop/electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ const { ipcRenderer, contextBridge } = require('electron')

// Hook the error handlers as early as possible
window.addEventListener('error', event => {
ipcRenderer.invoke('handle-error', "Preload Context Error", event.error || event)
if (event.error && event.error.message) {
ipcRenderer.invoke('handle-error', "Preload Context Error", {
message: event.error.message,
stack: event.error.stack
})
} else {
ipcRenderer.invoke('handle-error', "Preload Context Error", event.error || event)
}
event.preventDefault();
console.error(event.error || event)
})
Expand Down
9 changes: 8 additions & 1 deletion packages/desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { Electron } from 'shared/lib/electron'
import App from './App.svelte'

window.addEventListener('error', event => {
Electron.unhandledException("Render Context Error", event.error || event)
if (event.error && event.error.message) {
Electron.unhandledException("Render Context Error", {
message: event.error.message,
stack: event.error.stack
})
} else {
Electron.unhandledException("Render Context Error", event.error || event)
}
event.preventDefault();
console.error(event.error || event)
})
Expand Down
36 changes: 29 additions & 7 deletions packages/desktop/public/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@
}

::-webkit-scrollbar {
width: 8px;
width: 8px;
}

::-webkit-scrollbar-thumb {
background-color: #D8E3F5;
border-radius: 10px;
background-color: #D8E3F5;
border-radius: 10px;
}

::-webkit-scrollbar-track {
background-color: transparent;
background-color: transparent;
}
</style>
</head>
Expand Down Expand Up @@ -159,14 +161,34 @@ <h2>Unfortunately an error has occurred in Firefly.</h2>
document.getElementById('version').textContent = `App Version: ${errorData.version}`
document.getElementById('diagnostics').textContent = errorData.diagnostics
document.getElementById('errorType').textContent = `Error Type: ${errorData.errorType}`
document.getElementById('details').textContent = JSON.stringify(errorData.error || "")
document.getElementById('details').textContent = formatError()
})

function formatError() {
let formatted = []

if (errorData.error) {
if (errorData.error instanceof Error || errorData.error.stack || errorData.error.message) {
if (errorData.error.stack) {
formatted.push(errorData.error.stack)
} else if (errorData.error.message) {
formatted.push(errorData.error.message)
}
} else if (typeof errorData.error == 'string') {
formatted.push(errorData.error)
} else {
formatted.push(JSON.stringify(errorData.error))
}
}

return formatted.join('\r\n')
}

function copy() {
let content = `App Version: ${errorData.version}\r\n\r\n`
content += errorData.diagnostics + "\r\n\r\n"
content += `Error Type: ${errorData.errorType}` + "\r\n\r\n"
content += JSON.stringify(errorData.error || "")
content += formatError()
copyToClipboard(content)
}

Expand Down Expand Up @@ -195,4 +217,4 @@ <h2>Unfortunately an error has occurred in Firefly.</h2>
</script>
</body>

</html>
</html>

0 comments on commit 700c752

Please sign in to comment.