sorenlouv / backport

A simple CLI tool that automates the process of backporting commits on a GitHub repo
https://github.com/sqren/backport/blob/main/docs/config-file-options.md
Apache License 2.0
241 stars 57 forks source link

Hitting a null object error sporadically #497

Closed JoeSzymanskiFAN closed 2 months ago

JoeSzymanskiFAN commented 3 months ago

We have started making use of the backport CLI tool to do some backport automation with our repo and occasionally we are hitting an issue I can't quite track down. When we hit this issue, we are getting the following error:

{"status":"failure","commits":[],"error":{},"errorMessage":"Cannot read properties of null (reading '\''remoteConfigHistory'\'')"}

The redacted command we are running is:

backport --repo [redacted] \
         --accessToken [redacted] \
         --pullNumber 7979 \
         --noFork \
         --nonInteractive \
         --commitConflicts \
         --label "automated backport" \
         --source-branch "example-source-branch" \
         --target-branch "example-target-branch" \
         --dryRun

Most of the time, we see everything working, but sometimes this problem gets hit for a specific PR, and I haven't been able to get it working at all for that PR.

Any direction to investigate would be helpful.

sorenlouv commented 2 months ago

Can you check if the logs contain the stack trace for the error Cannot read properties of null (reading 'remoteConfigHistory')?

Logs are located in ~/.backport/

JoeSzymanskiFAN commented 2 months ago

I see the following at the end of the logs

{"level":"error","message":"Unhandled exception: Cannot read properties of null (reading 'remoteConfigHistory')","metadata":{"stack":"TypeError: Cannot read properties of null (reading 'remoteConfigHistory')
    at getSourceCommitBranchLabelMapping (/opt/homebrew/lib/node_modules/backport/dist/lib/sourceCommit/parseSourceCommit.js:144:56)
    at parseSourceCommit (/opt/homebrew/lib/node_modules/backport/dist/lib/sourceCommit/parseSourceCommit.js:21:44)
    at fetchCommitBySha (/opt/homebrew/lib/node_modules/backport/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js:46:54)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetchCommitsByPullNumber (/opt/homebrew/lib/node_modules/backport/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js:89:20)
    at async Promise.all (index 0)
    at async getCommits (/opt/homebrew/lib/node_modules/backport/dist/lib/getCommits.js:41:35)
    at async backportRun (/opt/homebrew/lib/node_modules/backport/dist/backportRun.js:61:19)"},"timestamp":"2024-04-03 15:36:07"}
sorenlouv commented 2 months ago

Thanks. The problem is happening here so it looks like there is no mergeCommit. Has the PR in question been merged?

https://github.com/sorenlouv/backport/blob/24dc0f87e68e2ca7986e138d363e04908d80e201/src/lib/sourceCommit/parseSourceCommit.ts#L281

JoeSzymanskiFAN commented 2 months ago

Yes, it has been merged via a squash into the source branch in question.

JoeSzymanskiFAN commented 2 months ago

Just want to confirm that I pulled the latest version directly and was able to finish a dry run against the PRs that previously were failing. I think I'll need this to be released at some point officially.

sorenlouv commented 2 months ago

Thanks for testing it, much appreciated! I've released the fix in v9.4.6