Bug 1441817 - Fix Error when console.count packet is incomplete; r=miker.
This currently happens in the browser console. The packet we receive
for console.count calls does not have the counter property which we
usually consume to display the counter label and data.
Here we prevent adding such messages, before a follow-up fix which should
be about adding those information in the packet.
For the record, it was not working either in the old frontend.
MozReview-Commit-ID: 1SiFgAHIziI
--- a/devtools/client/webconsole/new-console-output/test/store/messages.test.js
+++ b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
@@ -563,16 +563,28 @@ describe("Message reducer:", () => {
const { dispatch, getState } = setupStore();
const packet = stubPackets.get("console.dirxml(window)");
dispatch(actions.messagesAdd([packet]));
const dirxmlMessage = getLastMessage(getState());
expect(dirxmlMessage.level).toEqual(MESSAGE_TYPE.LOG);
});
+
+ it("does not throw when adding incomplete console.count packet", () => {
+ const { dispatch, getState } = setupStore();
+ const packet = clonePacket(stubPackets.get(`console.count('bar')`));
+
+ // Remove counter information to mimick packet we receive in the browser console.
+ delete packet.message.counter;
+
+ dispatch(actions.messagesAdd([packet]));
+ // The message should not be added to the state.
+ expect(getAllMessagesById(getState()).size).toBe(0);
+ });
});
describe("expandedMessageIds", () => {
it("opens console.trace messages when they are added", () => {
const { dispatch, getState } = setupStore();
const message = stubPackets.get("console.trace()");
dispatch(actions.messagesAdd([message]));
--- a/devtools/client/webconsole/new-console-output/utils/messages.js
+++ b/devtools/client/webconsole/new-console-output/utils/messages.js
@@ -81,19 +81,25 @@ function transformConsoleAPICallPacket(p
case "clear":
// We show a message to users when calls console.clear() is called.
parameters = [l10n.getStr("consoleCleared")];
break;
case "count":
// Chrome RDP doesn't have a special type for count.
type = MESSAGE_TYPE.LOG;
let {counter} = message;
- let label = counter.label ? counter.label : l10n.getStr("noCounterLabel");
- messageText = `${label}: ${counter.count}`;
- parameters = null;
+
+ if (!counter) {
+ // We don't show anything if we don't have counter data.
+ type = MESSAGE_TYPE.NULL_MESSAGE;
+ } else {
+ let label = counter.label ? counter.label : l10n.getStr("noCounterLabel");
+ messageText = `${label}: ${counter.count}`;
+ parameters = null;
+ }
break;
case "time":
parameters = null;
if (timer && timer.error) {
messageText = l10n.getFormatStr(timer.error, [timer.name]);
level = MESSAGE_LEVEL.WARN;
} else {
// We don't show anything for console.time calls to match Chrome's behaviour.