diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-29 17:58:35 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-29 17:58:35 -0400 |
| commit | cfffd35f2da32abec0f5ad865144342f73fa092b (patch) | |
| tree | edcd6b0403e22dc1ff8ebf50886acc97733d3126 /docs/repl.js | |
| parent | 4aab121d1720ebb8ca2c59b82dc86beeb4593c6d (diff) | |
Stack trace for runtime errors
Diffstat (limited to 'docs/repl.js')
| -rw-r--r-- | docs/repl.js | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/docs/repl.js b/docs/repl.js index da06e383..e9158b12 100644 --- a/docs/repl.js +++ b/docs/repl.js @@ -14,22 +14,23 @@ let repl = ()=>{ try { doc.rslt.textContent=fmt(bqn(s)); } catch(e) { - let r=e.src, w=e.message, is=null; - if (r==='Compiler'&&w.sh[0]===2) [is,w]=w; - if (r==='!') w=w?fmt(w).replace(/^/gm,'! '):'! Error'; - else w=w.sh?w.join(''):w; - if (is!==null) { + console.log(e); + let r=e.src, w=e.message, loc=[]; + while (w.sh&&w.sh[0]===2) { + let is; [is,w]=w; let n=is.sh?is.sh[0]:0, i=n?is[0]:is; let to=i=>Array.from(s).slice(0,i).join('').split('\n'); let ll=to(i), l=ll.length-1, j=ll[l].length, m=to()[l]; let k=1,o=i-j,cl=j; while (k<n&&(cl=is[k]-o)<m.length) k++; let c=Array(cl).fill(0); c[j]=1; for (let h=1;h<k;h++) c[is[h]-o]=1; - w = [w,'',m,c.map(t=>t?'^':' ').join('')].join('\n'); - if (k<n) w+='\n'+'(and other lines)'; + let add = ['',m,c.map(t=>t?'^':' ').join('')]; + loc = add.concat(k<n?['(and other lines)']:[], loc); } + if (r==='!') w=w?fmt(w).replace(/^/gm,'! '):'! Error'; + else w=w.sh?w.join(''):w; doc.rslt.classList.add('err'); - doc.rslt.textContent=w; + doc.rslt.textContent=[w].concat(loc).join('\n'); } }, 0); } |
