Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

375
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda