| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 98e54b0 commit 455e6f1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,13 +38,17 @@ const inspectDefaultOptions = Object.seal({ | |||
| 38 | 38 | breakLength: 60 | |
| 39 | 39 | }); | |
| 40 | 40 | ||
| 41 | + const CIRCULAR_ERROR_MESSAGE = 'Converting circular structure to JSON'; | ||
| 42 | + | ||
| 41 | 43 | var Debug; | |
| 42 | 44 | ||
| 43 | 45 | function tryStringify(arg) { | |
| 44 | 46 | try { | |
| 45 | 47 | return JSON.stringify(arg); | |
| 46 | - } catch (_) { | ||
| 47 | - return '[Circular]'; | ||
| 48 | + } catch (err) { | ||
| 49 | + if (err.name === 'TypeError' && err.message === CIRCULAR_ERROR_MESSAGE) | ||
| 50 | + return '[Circular]'; | ||
| 51 | + throw err; | ||
| 48 | 52 | } | |
| 49 | 53 | } | |
| 50 | 54 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,6 +86,16 @@ assert.strictEqual(util.format('o: %j, a: %j'), 'o: %j, a: %j'); | |||
| 86 | 86 | assert.strictEqual(util.format('%j', o), '[Circular]'); | |
| 87 | 87 | } | |
| 88 | 88 | ||
| 89 | + { | ||
| 90 | + const o = { | ||
| 91 | + toJSON() { | ||
| 92 | + throw new Error('Not a circular object but still not serializable'); | ||
| 93 | + } | ||
| 94 | + }; | ||
| 95 | + assert.throws(() => util.format('%j', o), | ||
| 96 | + /^Error: Not a circular object but still not serializable$/); | ||
| 97 | + } | ||
| 98 | + | ||
| 89 | 99 | // Errors | |
| 90 | 100 | const err = new Error('foo'); | |
| 91 | 101 | assert.strictEqual(util.format(err), err.stack); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments