Skip to content

Commit

Permalink
Merge pull request #13 from dylibso/json-fail
Browse files Browse the repository at this point in the history
feat: show text representation when json parsing fails
  • Loading branch information
mhmd-azeez authored Sep 16, 2024
2 parents c0d8747 + 43a4aba commit 8db24b9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export class MemoryView extends DataView {

// Get the JSON representation of a value stored in Extism memory
json(): any {
return JSON.parse(this.text());
try {
return JSON.parse(this.text());
} catch (e) {
const text = this.text();
throw new Error(`Failed to parse JSON: ${text}. Error: ${e.message}`);
}
}

// Get the string representation of a value stored in Extism memory
Expand Down

0 comments on commit 8db24b9

Please sign in to comment.