joshcai / leetcode-sync

GitHub Action for syncing LeetCode submissions to GitHub
293 stars 59 forks source link

Fix error while committing a locked problem with an accepted solution. #59

Closed Darshan-AS closed 4 months ago

Darshan-AS commented 4 months ago

Came across the below error on a recent run:

[Sun, 28 Apr 2024 19:56:01 GMT] Syncing 1480 submissions...
[Sun, 28 Apr 2024 19:56:01 GMT] Got info for submission #321203125
[Sun, 28 Apr 2024 19:56:01 GMT] Getting question data for counting-elements...
[Sun, 28 Apr 2024 19:56:01 GMT] Committing solution for counting-elements...
[Sun, 28 Apr 2024 19:56:01 GMT] HttpError: Must supply either tree.sha or tree.content. Request will be rejected if both are present.
    at /home/runner/work/_actions/joshcai/leetcode-sync/v1.6/dist/index.js:6540:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async commit (/home/runner/work/_actions/joshcai/leetcode-sync/v1.6/dist/index.js:14666:24)
    at async Object.sync (/home/runner/work/_actions/joshcai/leetcode-sync/v1.6/dist/index.js:14914:34)
    at async main (/home/runner/work/_actions/joshcai/leetcode-sync/v1.6/dist/index.js:19564:3)
Error: HttpError: Must supply either tree.sha or tree.content. Request will be rejected if both are present.

Turns out the problem counting-elements is a locked/premium problem. As a consequence, fetching the questionData yields null, which then leads to an empty tree.content in the commit, causing the above error.

Interestingly, I do seem to have an accepted solution for the problem in my submission history. And, No, I wasn't on leetcode premium in the past.

I'm guessing, counting-elements started off as an open problem, but was locked sometime after I'd solved it.

As a hotfix for my personal use, I've wrapped questionData in a template literal. Please feel free to add appropriate fallback text and logs as you deem fit.

Also, shot myself in the foot with the git add . in the pre-commit. Hence a tiny tweak.

PS. Thanks for the good work, Josh. Very nifty tool!