coming from java to nodejs whats the convention for error handling logging? e.message or e.stack?

I come from java, when I got an expected error I printed stack traces. I’m coming now to work on nodejs (never really worked on javascript). and in the nodejs project which I need to maintain (project was already coded by other javascript developers) I see error logging following:

logger.error('some message ' + e.message)


logger.error('some message ' + e);


logger.error('some message ' + e.toString());


logger.error('some message');

I saw no stacktraces in logs.
Coming from java I converted a few errors to:

logger.error('some message ' + e.stack)

but then when a peer javascript developer reviewed that he had a bad eye on me and asked me why do I do that? I told him if the error is unexpected we want all the information about it. He was very upset that I want the stack and not the message, his claim is that it would clutter the logs, so I said but the error is unexpected, he told me this is nodejs here no stacktraces here. I still want .stack but all the javascript developers do not want it they think it’s bad practice to print the .stack, I feel I lose important information. We ended up by him changing my .stack to .message.

I looked at logs and sometimes the .stack just prints two lines not much of a stack, however for me the first line where it printed the filename and the line number where the problem happened is justifying the stack, the javascript developer claim in this case was I can search the error message in code and find it, for me that is not suffice because i don’t think this is scalable a day would come where we would find multiple places with the same printing and if we had a stack we would know exactly which file printed the error and in certain cases also have stack.

Coming from java to javascript – am i missing something? should I do e.message and not e.stack? am i taking something from java that i should not be?



Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *