| 669 | * @param {*} e Event object to extract error details from |
| 670 | */ |
| 671 | const fesErrorMonitor = e => { |
| 672 | if (p5.disableFriendlyErrors) return; |
| 673 | |
| 674 | // Don't try to handle an error intentionally emitted by FES to halt execution |
| 675 | if (e && (e instanceof FESError || e.reason instanceof FESError)) return; |
| 676 | |
| 677 | // Try to get the error object from e |
| 678 | let error; |
| 679 | if (e instanceof Error) { |
| 680 | error = e; |
| 681 | } else if (e instanceof ErrorEvent) { |
| 682 | error = e.error; |
| 683 | } else if (e instanceof PromiseRejectionEvent) { |
| 684 | error = e.reason; |
| 685 | if (!(error instanceof Error)) return; |
| 686 | } |
| 687 | if (!error) return; |
| 688 | |
| 689 | let stacktrace = p5._getErrorStackParser().parse(error); |
| 690 | // process the stacktrace from the browser and simplify it to give |
| 691 | // friendlyStack. |
| 692 | let [isInternal, friendlyStack] = processStack(error, stacktrace); |
| 693 | |
| 694 | // if this is an internal library error, the type of the error is not relevant, |
| 695 | // only the user code that lead to it is. |
| 696 | if (isInternal) { |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | const errList = errorTable[error.name]; |
| 701 | if (!errList) return; // this type of error can't be handled yet |
| 702 | let matchedError; |
| 703 | for (const obj of errList) { |
| 704 | let string = obj.msg; |
| 705 | // capture the primary symbol mentioned in the error |
| 706 | string = string.replace(new RegExp('{{}}', 'g'), '([a-zA-Z0-9_]+)'); |
| 707 | string = string.replace(new RegExp('{{.}}', 'g'), '(.+)'); |
| 708 | string = string.replace(new RegExp('{}', 'g'), '(?:[a-zA-Z0-9_]+)'); |
| 709 | let matched = error.message.match(string); |
| 710 | |
| 711 | if (matched) { |
| 712 | matchedError = Object.assign({}, obj); |
| 713 | matchedError.match = matched; |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | if (!matchedError) return; |
| 719 | |
| 720 | // Try and get the location from the top element of the stack |
| 721 | let locationObj; |
| 722 | if ( |
| 723 | stacktrace && |
| 724 | stacktrace[0].fileName && |
| 725 | stacktrace[0].lineNumber && |
| 726 | stacktrace[0].columnNumber |
| 727 | ) { |
| 728 | locationObj = { |
nothing calls this directly
no test coverage detected