Skip to content

Commit

Permalink
feat: show text representation when json parsing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Sep 16, 2024
1 parent c0d8747 commit 43a4aba
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 43a4aba

Please sign in to comment.