Page MenuHomePhabricator

[wm-checks-api] error: changeMessage.real_author is undefined
Closed, ResolvedPublic

Description

This happens on some old changesets where there wouldn't be any relevant results anyway, but the error is currently shown not just in the console, it is shown on the page as well. I'm reporting that it is shown to users, not that it has no results (that seems fine).

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Kartographer/+/304151

Screenshot 2023-01-31 at 19.17.08.png (230×1 px, 53 KB)

[wm-checks-api] error TypeError: changeMessage.real_author is undefined
@ accept()
@ filterMessages()

Event Timeline

That is definitely on me, the code is not very robust. The plugin process all of the messages and pass each of them to the various robots implementations which then returns whether they accept or reject the given message. I believe this one comes from the SonarQubeProcessor:

/**
 * Process SonarQube reports
 *
 * https://github.com/kostajh/sonarqubebot/
 */
class SonarQubeProcessor extends BotProcessor {

  /**
   * @param {ChangeMessageInfo} changeMessage
   * @return {boolean} Whether the message can be parsed
   */
  accept(changeMessage) {
    return changeMessage.real_author.username === 'sonarqubebot';
  }

The changeMessage is a ChangeMessageInfo type:

export declare interface ChangeMessageInfo {
  id: ChangeMessageId;
  author?: AccountInfo;
  reviewer?: AccountInfo;
  updated_by?: AccountInfo;
  real_author?: AccountInfo;
  date: Timestamp;
  message: string;
  accounts_in_message?: AccountInfo[];
  tag?: ReviewInputTag;
  _revision_number?: PatchSetNum;
}

real_author is an optional field indeed.

For the given change, it seems to be the message about Yurik being added automatically as a reviewer, the message object has:

_revision_number: 1
author: Object { _account_id: 571, name: "Yurik", email: "yuriastrakhan@gmail.com", … }
commentThreads: Array []
date: "2016-08-11 00:37:58.500000000"
​expanded: true
​isImportant: true
​tag: "autogenerated:gerrit:reviewerUpdate"
​type: "REVIEWER_UPDATE"
​updates: Array [ {
  message: "Added to reviewer: "
​  reviewers: Array [ {
    0: Object { _account_id: 571, name: "Yurik", email: "yuriastrakhan@gmail.com", … }
​​​​    length: 1
} ]

CindyTheBrowserBot would have the same issue. I guess I should filter out any message not having real_author which would be in:

async fetch(change) {
...
  filterMessages(messages) {
    return messages.filter(m => {
      // Filter out Gerrit builtin messages
      if ( typeof m.tag !== 'undefined' && m.tag.startsWith('autogenerated:gerrit:') ) {
        return false;
      }
      for (const processor of this.processors) {
        if ( processor.accept(m) ) {
          return true;
        }
      }
      return false;
    });
  }

But that already filters out based on tag starting with autogenerated:gerrit. So the condition must be triggered by another message.

The Change has been successfully merged by jenkins-bot message does not have a real_author:

3: Object { id: "22d93b9b657a158da273f6146f40287c71778637", date: "2016-08-11 00:41:44.000000000", message: "Change has been successfully merged by jenkins-bot", … }
​​_index: 3
​​_revision_number: 1
​​accounts_in_message: Array []
​​commentThreads: Array []
​​date: "2016-08-11 00:41:44.000000000"
​​expanded: false
​​id: "22d93b9b657a158da273f6146f40287c71778637"
​​isImportant: true
​​message: "Change has been successfully merged by jenkins-bot"
tag: undefined

Whereas if I take the same kind of message on a recent change such as https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/885321, it has a real_author set:

Object { id: "c7566be2584b992dc925e68c1e3ab7db1e81c8f2", tag: "autogenerated:gerrit:merged", author: {…}, real_author: {…}, date: "2023-02-01 08:39:04.000000000", message: "Change has been successfully merged", accounts_in_message: [], _revision_number: 4, _index: 13, expanded: false, … }
​_index: 13
​_revision_number: 4
​accounts_in_message: Array []
​author: Object { _account_id: 75, name: "jenkins-bot", username: "jenkins-bot", … }
​commentThreads: Array []
​date: "2023-02-01 08:39:04.000000000"
​expanded: false
​id: "c7566be2584b992dc925e68c1e3ab7db1e81c8f2"
​isImportant: true
​message: "Change has been successfully merged"
​real_author: Object { _account_id: 75, name: "jenkins-bot", username: "jenkins-bot", … }
​tag: "autogenerated:gerrit:merged"

Change 938318 had a related patch set uploaded (by Hashar; author: Paladox):

[operations/software/gerrit@deploy/wmf/stable-3.5] wm-checks-api: check undefined real_author

https://gerrit.wikimedia.org/r/938318

Change 938318 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.5] wm-checks-api: check undefined real_author

https://gerrit.wikimedia.org/r/938318

Mentioned in SAL (#wikimedia-operations) [2023-07-17T04:08:51Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@cad3002]: wm-checks-api: check undefined real_author - T328484

Mentioned in SAL (#wikimedia-operations) [2023-07-17T04:08:59Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@cad3002]: wm-checks-api: check undefined real_author - T328484 (duration: 00m 08s)

Change 938472 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.5] wm-checks-api: check undefined real_author (2)

https://gerrit.wikimedia.org/r/938472

Change 938472 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.5] wm-checks-api: check undefined real_author (2)

https://gerrit.wikimedia.org/r/938472

Mentioned in SAL (#wikimedia-operations) [2023-07-17T04:33:08Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@1153a16]: wm-checks-api: check undefined real_author (2) - T328484

Mentioned in SAL (#wikimedia-operations) [2023-07-17T04:33:16Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@1153a16]: wm-checks-api: check undefined real_author (2) - T328484 (duration: 00m 08s)

hashar reassigned this task from hashar to Paladox.