Skip to content

Commit

Permalink
fix: show stacktrace from wasm in logs
Browse files Browse the repository at this point in the history
Triggered by #1466
  • Loading branch information
Jolg42 committed Jul 26, 2023
1 parent 3fc8b1f commit d10381b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions packages/language-server/src/prisma-schema-wasm/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ export function getCliVersion(): string {
export function handleWasmError(e: Error, cmd: string, onError?: (errorMessage: string) => void) {
const getErrorMessage = () => {
if (isWasmPanic(e)) {
const { message } = getWasmError(e)
const { message, stack } = getWasmError(e)
const msg = `prisma-schema-wasm errored when invoking ${cmd}. It resulted in a Wasm panic.\n${message}`

return { message: msg, isPanic: true }
return { message: msg, isPanic: true, stack }
}

const msg = `prisma-schema-wasm errored when invoking ${cmd}.\n${e.message}`
return { message: msg, isPanic: false }
return { message: msg, isPanic: false, stack: e.stack }
}

const { message, isPanic } = getErrorMessage()
const { message, isPanic, stack } = getErrorMessage()

if (isPanic) {
console.error(message)
console.warn(`prisma-schema-wasm errored (panic) with: ${message}\n\n${stack}`)
} else {
console.warn(message)
console.warn(`prisma-schema-wasm errored with: ${message}\n\n${stack}`)
}

if (onError) {
onError(
"prisma-schema-wasm errored. To get a more detailed output please see Prisma Language Server output. You can do this by going to View, then Output from the toolbar, and then select 'Prisma Language Server' in the drop-down menu.",
// Note: VS Code strips newline characters from the message
`prisma-schema-wasm errored with: -- ${message} -- For the full output check the "Prisma Language Server" output. In the menu, click View, then Output and select 'Prisma Language Server' in the drop-down menu.`,
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export function startServer(options?: LSOptions): void {
// return result
// }

function showErrorToast(errorMessage: string) {
// Note: VS Code strips newline characters from the message
function showErrorToast(errorMessage: string): void {
connection.window.showErrorMessage(errorMessage)
}

Expand Down

0 comments on commit d10381b

Please sign in to comment.