1

I have a problem where the console will log an error twice when using \n in the error message.

Here is an example:

throw new Error("Vector lengths must be equal");

The code above results in :
Error: Vector lengths must be equal

As you can see this error message has printed once as expected.

throw new Error("Vector lengths must be equal" + "\nVector[0] = 1");

The code above results in :
Error: Vector lengths must be equal
Vector[0] = 1
Error: Vector lengths must be equal
Vector[0] = 1

Here, I have added \n in the error message to create a break in the error message for increased readability, but as you can see it prints the error message twice which is unexpected and repetitive.

Please advise me in any way on how I can work around or even fix this problem.

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • 1
    I can't reproduce the issue in FF nor in Chromium browsers. On which environment are you testing? – Teemu Apr 08 '22 at 04:18
  • 1
    I can't reproduce this. Highly doubt it will work but try it without `+` Example: `throw new Error("Vector lengths must be equal\nVector[0] = 1");` – Michael Rogers Apr 08 '22 at 04:20
  • @Teemu I am using an online IDE called replit and I have now tried testing my code locally and the error mentioned is not produced. So, I believe there may just be something wrong with the IDE that creates this error. – Yipee Coder Apr 08 '22 at 04:26
  • Maybe you should report a bug. If Michael's suggestion won't fix the issue, there's probably not much we can do here at SO. – Teemu Apr 08 '22 at 04:38

0 Answers0