tslog icon indicating copy to clipboard operation
tslog copied to clipboard

tslog should not modify the Error prototype

Open jonahsnider opened this issue 4 years ago • 3 comments

https://github.com/watson/error-callsites/blob/1d6e6cc416b56d535c608ed77980867bb7b345c9/index.js#L8-L21

https://github.com/fullstack-build/tslog/blob/77ab7c9331d0bc6f627fa7a4e45a4eebc8908a01/src/CallSitesHelper.ts#L64-L78

tslog should not modify the global Error prototype. If modifying the prototype is necessary for certain features it should be explicitly enabled with an option.

This can cause issues in otherwise working code. For example, in a working API server, introducing tslog caused error handling code to crash the app instead of responding to an HTTP request.

jonahsnider avatar Mar 02 '21 17:03 jonahsnider

Thank you for your input. We use this to access native v8 stack information. I will put some thought into this issue.

terehov avatar Mar 11 '21 13:03 terehov

Somewhat related - Node has native support for sourcemaps (via --enable-source-maps), and this feature breaks as soon as tslog is required anywhere the application because prepareStackTrace is hijacked by the library. We use TypeScript, and have to add delete Error.prepareStackTrace immediately after including tslog to restore the expected behavior.

eugene1g avatar Jul 30 '21 18:07 eugene1g

@eugene1g Thank you for this hint!

terehov avatar Jul 30 '21 18:07 terehov

There is a new, completely rewritten version (4.0) which does not interfere with the Error object any more. And yes, we are now completely dependency free and use the native supported source maps. Give it a go and let me know if that solves your problem:

  • npm i tslog@next

  • and run it with node --enable-source-maps or for TypeScript node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm

Thank you.

terehov avatar Sep 30 '22 12:09 terehov

V4 is released now, so I'm going to close this issue. Feel free to open a new one if V4 didn't solve it for you.

Here are the docs: tslog.js.org

terehov avatar Nov 15 '22 18:11 terehov

still facing this issue with the command option you provide..

ShinJustinHolly3317 avatar Dec 20 '22 06:12 ShinJustinHolly3317

@ShinJustinHolly3317 More details please. Did you upgrade to V4? It won’t help with V3.

terehov avatar Dec 20 '22 06:12 terehov

sorry for my ambiguous question, and just ignore it.

Please kindly read my question below :)

I'm using [email protected] currently with Typescript, and what I'm facing is that the logger always show the property stack in every class inheriting from native Error class.

Is there any way to prevent the stack property showing? Cause from our development convention, we use our custom Error class as response (we're using Express as server framework).

*remarks for the stack I talk about is this

stack: IStackFrame[];

in argumentsArray of interface ILogObject

ShinJustinHolly3317 avatar Dec 20 '22 07:12 ShinJustinHolly3317

@ShinJustinHolly3317 I understand your request, and that's why I rewrote tslog completely to not interfere with the native Error instance any more, which was used to access the underlying V8 meta information.

Is there a reason why you prefer to stick to V3 instead of upgrading to V4?

terehov avatar Dec 20 '22 08:12 terehov

@terehov Cause there will be some check and migration work (team legacy). Just asking if there is any other way to work around.

and also I did't find explanation or example for overwritingConsole. Just curious if this option still works?

ShinJustinHolly3317 avatar Dec 20 '22 08:12 ShinJustinHolly3317

@terehov Cause there will be some check and migration work (team legacy). Just asking if there is any other way to work around.

I see. I can help you with migration of tslog, if it helps.

and also I did't find explanation or example for overwritingConsole. Just curious if this option still works?

Unfortunately not, since console is the default output in V4, plus you can easily add this functionality from outside the library.

terehov avatar Dec 20 '22 08:12 terehov

@terehov Cause there will be some check and migration work (team legacy). Just asking if there is any other way to work around.

I see. I can help you with migration of tslog, if it helps.

and also I did't find explanation or example for overwritingConsole. Just curious if this option still works?

Unfortunately not, since console is the default output in V4, plus you can easily add this functionality from outside the library.

Thank you, helps a lot. Let me have a discussion with my team which way is better.

ShinJustinHolly3317 avatar Dec 20 '22 09:12 ShinJustinHolly3317