tslog icon indicating copy to clipboard operation
tslog copied to clipboard

Bug: Stack trace parsing breaks with parentheses

Open dever23b opened this issue 2 years ago • 5 comments

Describe the bug TS Log fails to produce proper stack traces when file paths contain parenthesis. When it encounters the parentheses it doesn't expect, the resulting formatted error message has "error stack: " and an asterisk for every line of the trace, but no content.

Example:

2023-06-14 23:04:11.939	WARN		Auth:Service	
 JWTExpired  "exp" claim timestamp check failed
error stack:
  • 	
	
  • 	
	
  • 	
	
  • 	
	
  • 	

To Reproduce Steps to reproduce the behavior:

  1. Create a file that has a path containing parenthesis
  2. Create an error from that file
  3. Log that error with a Logger instance

Expected behavior The error should display a proper stack trace

Screenshots If applicable, add screenshots to help explain your problem.

Additional context The culprit seems to be here. This regex causes fullFilePath to be incomplete and the logic that follows eventually discards the line, resulting in incomplete error messages.

Node.js Version 16.17.0

TS Log Version 4.8.2

dever23b avatar Jun 15 '23 00:06 dever23b

Upon further development, I'm just now noticing that when tslog executes in the browser context, it prints errors properly despite the parenthesis in the pathnames. So, now I'm more confused as to why it doesn't work from the node context.

dever23b avatar Jul 01 '23 02:07 dever23b

I was able to create a workaround by changing the regex in the aforementioned stackLineToStackFrame function to /\((.+)\)/. Therefore, I think I have confirmed that the issue is indeed caused by the regex in the link from above.

Unfortunately, due to #241, implementing the simple workaround required re-creating approx 230 lines worth of extraneous functions and some shady imports directly from the node_modules folder to access unexposed types, thereby effectively disconnecting a significant portion of the code from the TsLog codebase and future updates. The workaround serves as a proof of concept, I guess, but I can't recommend it as a solution due to the significant portions of code that had to be localized and will inevitably become obsolete.

dever23b avatar Jul 02 '23 04:07 dever23b

Does this problem still exist? It works on my mac with V.4.8.7

Screenshot 2023-08-07 at 23 09 25

terehov avatar Aug 07 '23 21:08 terehov

It's not working with regular ones:

> [email protected] dev-ts
> nodemon example(s/nodejs/index2.ts

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `nodemon example(s/nodejs/index2.ts'

terehov avatar Aug 07 '23 21:08 terehov

I'm still getting this with Next.js app router paths which may have parentheses. Please open the ticket again :-) v4.9.2

Industrial avatar Jun 05 '24 19:06 Industrial