Skip to content

Commit

Permalink
Include error from wasm module in pretty print error message
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Apr 18, 2023
1 parent 33d820d commit bff8677
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion expressjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"serve": "npm run build:prepare && bpm run serve:only",
"serve:only": "node src/index",
"test:ci": "npm run build:prepare && npm run lint && npm run test:jest",
"test:jest:watch": "npm run build:prepare && jest --watch",
"test:jest:watch": "npm run build:prepare && jest --watchAll",
"test:jest": "npm run build:prepare && jest --detectOpenHandles --coverage",
"lint:eslint": "eslint .",
"build:prepare": "npm run build:cache-git && npm run build:extract-webjar",
Expand Down
9 changes: 6 additions & 3 deletions expressjs/src/routes/events/pretty-print.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PrinterFactory {
// Instantiate the WASI module
const instance = await wasi.instantiate(module, {})

return new Printer({ instance })
return new Printer({ instance, wasi })
}
}

Expand All @@ -37,10 +37,12 @@ class Printer {
*
* @param {Object} v - the params object
* @param {WebAssembly.Instance} v.instance - the WebAssembly instance
* @param {WASI} v.wasi - the WASI instance
*/
constructor({ instance }) {
constructor({ instance, wasi }) {
this.mem = instance.exports.memory
this.fn = instance.exports.pp_print
this.wasi = wasi
}

/**
Expand All @@ -56,7 +58,8 @@ class Printer {

const rc = this.fn(0)
if (rc !== 0) {
throw new Error(`pp_print() returned ${rc}`)
const err = this.wasi.getStderrString()
throw new Error(`pp_print(${rc}): ${err}\nce: ${message}`)
}

return readFromMemory(this.mem)
Expand Down
2 changes: 1 addition & 1 deletion frontend/scripts/webjar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const webjars: Webjar[] = [{
const tmpDir = os.tmpdir()
const tmp = await fs.mkdtemp(`${tmpDir}/wasm-oci-`)
const reg = new WasmRegistry(tmp)
const image = Image.parse('quay.io/cardil/cloudevents-pretty-print@sha256:01b30983dda5eb42a8baefb523eb50d7d0e539fb10d7ab9498a2a59f35036afb')
const image = Image.parse('quay.io/cardil/cloudevents-pretty-print@sha256:134269c7090bcb923d8b8764920bb25923e38411413eac7e4240524f1a40dc74')
log(`Pulling image: ${green(image.toString())}`)
const wasm = await reg.pull(image)
p.addFile('META-INF/cloudevents-pretty-print.wasm', await fs.readFile(wasm.file), 'Wasm')
Expand Down

0 comments on commit bff8677

Please sign in to comment.