Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda