Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

379
Views
The console.trace() function log only the current function instead of the whole stacktrace

I am having trouble debugging my code, and the console.trace function seems to behave weirdly.

I have a code such as:

func1() {  
   console.trace("hey");  
}  
   
func2() {  
   func1();  
}

func2();

The resulting log looks like this:

"hey"  
func1 @ script.js:2

This is not really helpful as you can see. What could explain this kind of behaviour ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In your example,the behavior of console.trace([message][, ...args]) is exactly what is expected

Explanation

const func1 = () => {
  console.trace("hey");
}

const func2 = () => {
  func1();
}

func2();

Here

  1. func2 is called
  2. func2 calls func1
  3. func1 program halts and emit a stack trace.
  Trace: hey 
     at func1 (/script.js:2:11)
     at func2 (/script.js:6:3)
  • You can see from the above error, func1 was called by func2.

  • From this we understand which functions called each other.

  • We can also see the line number and file that the function exists on

  • The topmost line is the error message we passed.

  • The stack trace helps us to know the steps that lead up to our error.

  • Now we know where our stack trace generated which is in the func1.

  • That's why func1 is showing at the top. This will make our whole debugging process easier.

Please refer this:

  1. https://nodejs.org/api/console.html#consoletracemessage-args
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
about 4 years ago · Juan Pablo Isaza Report

0

While I'm not sure why console.trace() behaves like this, I did find a workaround as I needed proper stack traces. Simply replacing all console.trace(...) calls with console.log(..., (new Error()).stack) resulted in stack traces working, sometimes with far more detail.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!