• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
Add-ons
  1. MDN
  2. Mozilla
  3. Add-ons
  4. Thunderbird extensions
  5. Error reporting tools

Error reporting tools

In This Article
  1. errUtils New in Thunderbird 3
    1. Basic use case
    2. Event handler
    3. JavaScript object
    4. DOM elements
  2. log4moz
  3. Protocol logging

Currently, Thunderbird tends to eat a lot of exceptions. Some make it to the error console, most don't. There are deep fixes to the platform needed (e.g. bug 493414), but in the meantime, it would be helpful to be able to get useful output on stderr about exceptions, events and pretty-printed objects.

There are a couple of tools available for viewing exceptions: the errUtils module and the log4moz extension.

errUtils New in Thunderbird 3

The errUtils module contains a set of helper methods for debugging, such as logging exception objects, dumping DOM nodes, Events, and generic object dumps.

Basic use case

The basic use case is:

 Components.utils.import("resource://gre/modules/errUtils.js"); ...  try {  ... do stuff that might throw an exception }  catch (e) {  logException(e, true); // second arg is whether to rethrow }  

...which results in the following on the dump output:

-- EXCEPTION START --
+ message (string) 'a is not defined'
+ fileName (string) 'chrome://messenger/content/folderDisplay.js'
+ lineNumber (number) 483
+ stack (string) 428 chars
+ name (string) 'ReferenceError'
*
-- EXCEPTION END --
<top>
FolderDisplayWidget_show@chrome://messenger/content/folderDisplay.js:522
FolderPaneSelectionChange@chrome://messenger/content/commandglue.js:352
onselect@chrome://messenger/content/messenger.xul:1
[anonymous]@null:0
onxblmousedown@chrome://global/content/bindings/tree.xml:975

Event handler

 In an event handler, you can:

logEvent(event);

...and it will output stuff like:

-EVENT --------------------------
type: click
eventPhase: 3
target: [object HTMLSpanElement]
target.nodeName: span
target.id: null
currentTarget: [object HTMLDivElement]
currentTarget.nodeName: div
currentTarget.id: query-explanation
originalTarget: [object HTMLSpanElement]
originalTarget.nodeName: span
originalTarget.id: null
bubbles: true
cancelable: true
detail: 1
button: 0
isChar: false
shiftKey: false
altKey: false
ctrlKey: false
metaKey: false
clientX: 385
clientY: 30
screenX: 488
screenY: 156
layerX: 57
layerY: 30
isTrusted: true
timeStamp: 2080434436
-------------------------------------

JavaScript object

If faced with a generic JavaScript object, you can get detailed debugging output as follows. For example, given:

let x = {'foo': 123, 'bar': {'sub-key': 1, 'sub-key-2': 'tomato'}};

 Do:

logObject(x, 'x');

This yields:

Dumping Object: x
+ foo (number) 123
+ bar (object) [object Object]
| + sub-key (number) 1
| + sub-key-2 (string) 'tomato'
| *
*

DOM elements

 

If faced with a DOM element, you can print it out. For example:

logElement(document.getElementById('query-explanation', 'query-explanation'))

...yields:

<div
    id='query-explanation'
>
  <span
      class='explanation-fulltext-label'
  >
    <#text
        Searching for'
  </span>
  <span
      class='explanation-fulltext-term'
  >
    <#text
        gloda'
  </span>
</div>

log4moz

The Mozilla Labs log4moz interface is a partial implementation of Apache's log4* project (for example, log4j). To use it, create one or more appenders while initializing your add-on, and create loggers in the places where you have logging messages to emit. Minimum log levels to allow you to customize your logging output without changing any code.

Protocol logging

Activity regarding specific protocols (such as IMAP, SMTP, etc) can be logged by setting environment variables that specify the protocol and degree of verbosity in the log. This is explained on the MailNews Logging page on the Mozilla wiki.

Document Tags and Contributors

Tags: 
  • thunderbird
 Contributors to this page: wbamberg, jenzed
 Last updated by: wbamberg, Jan 15, 2016, 11:04:57 AM
See also
  1. WebExtensions
  2. Getting started
    1. Prerequisites
    2. Anatomy of a WebExtension
    3. Packaging and Installation
    4. Walkthrough
    5. Examples
  3. Guides
    1. Content scripts
    2. Porting from Google Chrome
    3. Match patterns
    4. Debugging
    5. Chrome incompatibilities
  4. JavaScript APIs
    1. alarms
    2. bookmarks
    3. browserAction
    4. contextMenus
    5. cookies
    6. events
    7. extension
    8. extensionTypes
    9. i18n
    10. idle
    11. notifications
    12. pageAction
    13. runtime
    14. storage
    15. tabs
    16. webNavigation
    17. webRequest
    18. windows
  5. Manifest keys
    1. applications
    2. background
    3. browser_action
    4. content_scripts
    5. default_locale
    6. description
    7. icons
    8. manifest_version
    9. name
    10. page action
    11. permissions
    12. version
    13. web_accessible_resources
  6. Add-on SDK
  7. Getting started
    1. Installation
    2. Getting started
    3. Troubleshooting
  8. High-Level APIs
    1. addon-page
    2. base64
    3. clipboard
    4. context-menu
    5. hotkeys
    6. indexed-db
    7. l10n
    8. notifications
    9. page-mod
    10. page-worker
    11. panel
    12. passwords
    13. private-browsing
    14. querystring
    15. request
    16. selection
    17. self
    18. simple-prefs
    19. simple-storage
    20. system
    21. tabs
    22. timers
    23. ui
    24. url
    25. widget
    26. windows
  9. Low-Level APIs
    1. /loader
    2. chrome
    3. console/plain-text
    4. console/traceback
    5. content/content
    6. content/loader
    7. content/mod
    8. content/symbiont
    9. content/worker
    10. core/heritage
    11. core/namespace
    12. core/promise
    13. dev/panel
    14. event/core
    15. event/target
    16. frame/hidden-frame
    17. frame/utils
    18. fs/path
    19. io/byte-streams
    20. io/file
    21. io/text-streams
    22. lang/functional
    23. lang/type
    24. loader/cuddlefish
    25. loader/sandbox
    26. net/url
    27. net/xhr
    28. places/bookmarks
    29. places/favicon
    30. places/history
    31. platform/xpcom
    32. preferences/event-target
    33. preferences/service
    34. remote/child
    35. remote/parent
    36. stylesheet/style
    37. stylesheet/utils
    38. system/child_process
    39. system/environment
    40. system/events
    41. system/runtime
    42. system/unload
    43. system/xul-app
    44. tabs/utils
    45. test/assert
    46. test/harness
    47. test/httpd
    48. test/runner
    49. test/utils
    50. ui/button/action
    51. ui/button/toggle
    52. ui/frame
    53. ui/id
    54. ui/sidebar
    55. ui/toolbar
    56. util/array
    57. util/collection
    58. util/deprecate
    59. util/list
    60. util/match-pattern
    61. util/object
    62. util/uuid
    63. window/utils
  10. Firefox for Android
  11. Getting started
    1. Walkthrough
    2. Debugging
    3. Code snippets
  12. APIs
    1. Accounts.jsm
    2. BrowserApp
    3. HelperApps.jsm
    4. Home.jsm
    5. HomeProvider.jsm
    6. JavaAddonManager.jsm
    7. NativeWindow
    8. Notifications.jsm
    9. PageActions.jsm
    10. Prompt.jsm
    11. Snackbars.jsm
    12. Sound.jsm
    13. Tab
  13. Legacy
  14. Restartless extensions
    1. Overview
  15. Overlay extensions
    1. Overview
  16. Themes
  17. Lightweight themes
    1. Overview
  18. Complete themes
    1. Overview
  19. Publishing add-ons
  20. Guides
    1. Signing and distribution overview
    2. Submit an add-on
    3. Review policies
    4. Developer agreement
    5. Featured add-ons
    6. Contact addons.mozilla.org
  21. Community and support
  22. Channels
    1. Add-ons blog
    2. Add-on forums
    3. Stack Overflow
    4. Development newsgroup
    5. IRC Channel