fullstack-build / tslog

📝 tslog - Universal Logger for TypeScript and JavaScript
https://tslog.js.org
MIT License
1.31k stars 61 forks source link

Bug: Stack trace parsing breaks with parentheses #240

Open dever23b opened 1 year ago

dever23b commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

terehov commented 1 year ago

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

Screenshot 2023-08-07 at 23 09 25
terehov commented 1 year ago

It's not working with regular ones:

> tslog@4.8.7 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'
Industrial commented 3 months ago

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