(error, stacktrace)
| 529 | * friendlyStack: the filtered (simplified) stacktrace |
| 530 | */ |
| 531 | const processStack = (error, stacktrace) => { |
| 532 | // cannot process a stacktrace that doesn't exist |
| 533 | if (!stacktrace) return [false, null]; |
| 534 | |
| 535 | stacktrace.forEach(frame => { |
| 536 | frame.functionName = frame.functionName || ''; |
| 537 | }); |
| 538 | |
| 539 | // isInternal - Did this error happen inside the library |
| 540 | let isInternal = false; |
| 541 | let p5FileName, friendlyStack, currentEntryPoint; |
| 542 | |
| 543 | // Intentionally throw an error that we catch so that we can check the name |
| 544 | // of the current file. Any errors we see from this file, we treat as |
| 545 | // internal errors. |
| 546 | try { |
| 547 | throw new Error(); |
| 548 | } catch (testError) { |
| 549 | const testStacktrace = p5._getErrorStackParser().parse(testError); |
| 550 | p5FileName = testStacktrace[0].fileName; |
| 551 | } |
| 552 | |
| 553 | for (let i = stacktrace.length - 1; i >= 0; i--) { |
| 554 | let splitted = stacktrace[i].functionName.split('.'); |
| 555 | if (entryPoints.includes(splitted[splitted.length - 1])) { |
| 556 | // remove everything below an entry point function (setup, draw, etc). |
| 557 | // (it's usually the internal initialization calls) |
| 558 | friendlyStack = stacktrace.slice(0, i + 1); |
| 559 | currentEntryPoint = splitted[splitted.length - 1]; |
| 560 | // We call the error "internal" if the source of the error was a |
| 561 | // function from within the p5.js library file, but called from the |
| 562 | // user's code directly. We only need to check the topmost frame in |
| 563 | // the stack trace since any function internal to p5 should pass this |
| 564 | // check, not just public p5 functions. |
| 565 | if (stacktrace[0].fileName === p5FileName) { |
| 566 | isInternal = true; |
| 567 | break; |
| 568 | } |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | // in some cases ( errors in promises, callbacks, etc), no entry-point |
| 574 | // function may be found in the stacktrace. In that case just use the |
| 575 | // entire stacktrace for friendlyStack |
| 576 | if (!friendlyStack) friendlyStack = stacktrace; |
| 577 | |
| 578 | if (isInternal) { |
| 579 | // the frameIndex property is added before the filter, so frameIndex |
| 580 | // corresponds to the index of a frame in the original stacktrace. |
| 581 | // Then we filter out all frames which belong to the file that contains |
| 582 | // the p5 library |
| 583 | friendlyStack = friendlyStack |
| 584 | .map((frame, index) => { |
| 585 | frame.frameIndex = index; |
| 586 | return frame; |
| 587 | }) |
| 588 | .filter(frame => frame.fileName !== p5FileName); |
no test coverage detected