-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
TSL: Introduce StackTrace
#32914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+326
−38
Merged
TSL: Introduce StackTrace
#32914
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e1f8620
introduce stack trace
sunag b3a31d9
Update StackTrace.js
sunag f8fd50e
Update Node.js
sunag d49bc5c
Update NodeError.js
sunag 297777f
add more StackTrace
sunag cc6f52f
improve StackTrace
sunag 7a47434
Capture stack trace for JavaScript errors
sunag cc644f3
improve alerts
sunag baeabf3
cleanup
sunag aeb6d85
Update StackTrace.js
sunag f89095b
Update StackTrace.js
sunag 1885346
improve inspector message
sunag 9c42df7
StackTrace: Rename `getError()` -> `getErrorMessage()`
sunag 088e2f6
more renames
sunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import StackTrace from './StackTrace.js'; | ||
|
|
||
| /** | ||
| * Custom error class for node-related errors, including stack trace information. | ||
| */ | ||
| class NodeError extends Error { | ||
|
|
||
| constructor( message, stackTrace = null ) { | ||
|
|
||
| super( message ); | ||
|
|
||
| /** | ||
| * The name of the error. | ||
| * | ||
| * @type {string} | ||
| */ | ||
| this.name = 'NodeError'; | ||
|
|
||
| /** | ||
| * The stack trace associated with the error. | ||
| * | ||
| * @type {?StackTrace} | ||
| */ | ||
| this.stackTrace = stackTrace; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export default NodeError; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Pre-compiled RegExp patterns for ignored files | ||
| const IGNORED_FILES = [ | ||
| /^StackTrace\.js$/, | ||
| /^TSLCore\.js$/, | ||
| /^.*Node\.js$/, | ||
| /^three\.webgpu.*\.js$/ | ||
| ]; | ||
|
|
||
| /** | ||
| * Parses the stack trace and filters out ignored files. | ||
| * Returns an array with function name, file, line, and column. | ||
| */ | ||
| function getFilteredTrace( stack ) { | ||
|
|
||
| // Pattern to extract: 1.Function, 2.File, 3.Line, 4.Column | ||
| const regex = /(?:at\s+)?([^@\s(]+)?(?:@|\s\()?.*?([^/)]+):(\d+):(\d+)/; | ||
|
|
||
| return stack.split( '\n' ) | ||
| .map( line => { | ||
|
|
||
| const match = line.match( regex ); | ||
| if ( ! match ) return null; // Skip if line format is invalid | ||
|
|
||
| return { | ||
| fn: match[ 1 ] || 'anonymous', // Function name | ||
| file: match[ 2 ].split( '?' )[ 0 ], // Clean file name (Vite/HMR) | ||
| line: parseInt( match[ 3 ], 10 ), // Line number | ||
| column: parseInt( match[ 4 ], 10 ) // Column number (Added back) | ||
| }; | ||
|
|
||
| } ) | ||
| .filter( frame => { | ||
|
|
||
| // Only keep frames that are valid and not in the ignore list | ||
| return frame && ! IGNORED_FILES.some( regex => regex.test( frame.file ) ); | ||
|
|
||
| } ); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Class representing a stack trace for debugging purposes. | ||
| */ | ||
| class StackTrace { | ||
|
|
||
| /** | ||
| * Creates a StackTrace instance by capturing and filtering the current stack trace. | ||
| */ | ||
| constructor() { | ||
|
|
||
| this.stack = getFilteredTrace( new Error().stack ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| export default StackTrace; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.