Replacing Cu.reportError with console.error

30 views
Skip to first unread message

Mark Banner

unread,
Nov 8, 2022, 9:15:34 AM11/8/22
to dev-pl...@mozilla.org, firefox-dev list

tl;dr We are thinking about replacing Cu.reportError with console.error, are there any cases which wouldn't be covered?


I noticed that there are some instances in our code where we have incorrectly tried to use Cu.reportError in the same way as console.error. We have tried to use the second argument as an additional string/standard object rather than the stack object that Cu.reportError is expecting.

This made me wonder about the differences between the two functions, and if we could move to the more standard console.error. There is a 10 year old bug suggesting that we could replace them.

As far as I can tell:

  • In single argument forms, these appear to be virtually identical when reporting to the browser console.
  • Cu.reportError never(?) gets reported to stdout, but console.error can be (via the devtools.console.stdout.* prefs).
  • The two argument form of Cu.reportError, could be replaced by generating an Error object and assigning the stack property on that error object.

We could very easily do a direct replacement for the majority of cases via ESLint tooling.

However, does anyone know of any cases that would not be covered when switching to console.error?

Mark

Reply all
Reply to author
Forward
0 new messages