Bug: console warning. messageServiceFromURI failed for undefined\ngetFcc@resource:///modules/MimeMessageUtils.jsm:194:14
Status: NEW
Priority: --
Created: 2020-10-26 02:15:39+00:00
Resolved: 2020-10-27 23:09:00+00:00

I see the following messages in my local mochitest log produced by
running FULL debug version of C-C TB.
It appears in console.warn, but since it seems a stacktrace of a sort,
I thought it may be worth looking into, and it seems to be reporting an error indirectly.

The tests that produces the message are noted as below with the message.
egrep "(messageServiceFromURI failed for undefined|TEST_START)" /FF-NEW/log1253-mochitest.txt 
(Somehow, newline is turned into "\n" in the stack trace of javascript error exception.)

```
119:50.82 TEST_START: comm/mail/test/browser/composition/browser_emlActions.js
120:01.99 GECKO(488007) console.warn: "messageServiceFromURI failed for undefined\ngetFcc@resource:///modules/MimeMessageUtils.jsm:194:14\ncreateAndSendMessage@resource:///modules/MessageSend.jsm:83:26\nCompleteGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4670:23\nGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4609:29\nSaveAsDraft@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4929:21\nSave@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4907:18\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:946:9\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:1181:9\ngoDoCommand@chrome://global/content/globalOverlay.js:101:18\noncommand@chrome://messenger/content/messengercompose/messengercompose.xhtml:1:12\nsynthesizeKey@chrome://mochikit/content/tests/SimpleTest/EventUtils.js:1210:11\ntest_reply_to_eml_save_as_draft@chrome://mochitests/content/browser/comm/mail/test/browser/composition/browser_emlActions.js:56:14\n"

126:12.86 TEST_START: comm/mail/test/browser/composition/browser_replyFormatFlowed.js
126:30.54 GECKO(488007) console.warn: "messageServiceFromURI failed for undefined\ngetFcc@resource:///modules/MimeMessageUtils.jsm:194:14\ncreateAndSendMessage@resource:///modules/MessageSend.jsm:83:26\nCompleteGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4670:23\nGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4609:29\nSaveAsDraft@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4929:21\nSave@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4907:18\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:946:9\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:1181:9\ngoDoCommand@chrome://global/content/globalOverlay.js:101:18\noncommand@chrome://messenger/content/messengercompose/messengercompose.xhtml:1:12\nsynthesizeKey@chrome://mochikit/content/tests/SimpleTest/EventUtils.js:1210:11\nsubtest_reply_format_flowed@chrome://mochitests/content/browser/comm/mail/test/browser/composition/browser_replyFormatFlowed.js:53:14\n"
126:38.48 GECKO(488007) console.warn: "messageServiceFromURI failed for undefined\ngetFcc@resource:///modules/MimeMessageUtils.jsm:194:14\ncreateAndSendMessage@resource:///modules/MessageSend.jsm:83:26\nCompleteGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4670:23\nGenericSendMessage@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4609:29\nSaveAsDraft@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4929:21\nSave@chrome://messenger/content/messengercompose/MsgComposeCommands.js:4907:18\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:946:9\ndoCommand@chrome://messenger/content/messengercompose/MsgComposeCommands.js:1181:9\ngoDoCommand@chrome://global/content/globalOverlay.js:101:18\noncommand@chrome://messenger/content/messengercompose/messengercompose.xhtml:1:12\nsynthesizeKey@chrome://mochikit/content/tests/SimpleTest/EventUtils.js:1210:11\nsubtest_reply_format_flowed@chrome://mochitests/content/browser/comm/mail/test/browser/composition/browser_replyFormatFlowed.js:53:14\n"
126:41.16 TEST_START: comm/mail/test/browser/composition/browser_replySignature.js
```

Looking at the code, I think it is more like a serious error than a
mere warning.

According the message, |originalMsgURI.spec| was "undefined".

https://searchfox.org/comm-central/source/mailnews/compose/src/MimeMessageUtils.jsm#194
(Aha, now I see why stacktrace contains "\n" as line separator. |e.stack| is turned into a string by embedding NEWLINE as "\n" and it is printed without special handling of backslash-escaped characters.)

```
        let msgHdr;
        try {
          msgHdr = Cc["@mozilla.org/messenger;1"]
            .createInstance(Ci.nsIMessenger)
            .messageServiceFromURI(originalMsgURI)
            .messageURIToMsgHdr(originalMsgURI); 
        } catch (e) {
-->       console.warn(
            `messageServiceFromURI failed for ${originalMsgURI.spec}\n${e.stack}`
          );
        }
        if (msgHdr) {
```

This is relatively new, I don't see it in the local log dated Sept 8,
but the errors were visible in local logs dated Sept 29 (only once then).
So it appeared somewhere in between.

The same warning (error?) is visible in other people's try-comm-centraal server
run as well.
For example, see the linux 64 debug version test runs.

Sat, Oct 24, 08:18:19 - thunderbird@calypsoblue.o
https://firefoxci.taskcluster-artifacts.net/C8bm4FBSSTuGKWiuwp4drg/0/public/logs/live_backing.log

Then I noticed I see a preceding error printed to console.debug when the messages are printed.
```
109:45.36 GECKO(723748) console.debug: "exception in getMsgHdr: [Exception... \"Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIMsgMessageService.messageURIToMsgHdr]\"  nsresult: \"0x80004005 (NS_ERROR_FAILURE)\"  location: \"JS frame :: chrome://openpgp/content/ui/enigmailMsgComposeOverlay.js :: getMsgHdr :: line 419\"  data: no]"

```

BTW, I have no idea why these are only printed to console.warn and console.debug.

My log summarizer did not pay attention to console.warn and
console.debug output very well before. (|make mozmill| basically
printed errors/warnings stadard output or equivalent, and so I never
bothered to pick up console.debug and console.warn messages. I have
added some code to handle console.error since |make mozmill| was
ditched in favor of mochitest in Dec 2019.  That is why I failed to
notice these messages earlier...

(Tough, the test logs are now split into multiple files and so the errors are spread over
mulitple files. This has been like this for some time. I wonder what
is the reationale behind this.)


PS: This could be somehow related to the following bug.

Bug 1635648 
enigmail - JavaScript Error: "NS_ERROR_FACTORY_NOT_REGISTERED: Component returned failure code: 0x80040154 (NS_ERROR_FACTORY_NOT_REGISTERED) [nsIMessenger.messageServiceFromURI]" {file: "chrome://openpgp/content/ui/enigmailMsgComposeOverlay.js" line: 483}