Bug (backend): dead null check in newQuotes.approve() — git === null never true, git init failure crashes with raw TypeError

Open Beginner friendly
#8,364 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Start in backend/src/dal/new-quotes.ts by comparing approve() around line 150 with the existing git availability check in add() at line 59, then inspect the module-level tryCatchSync initialization. Reproduce or reason through a failed simpleGit initialization and confirm that approving a quote returns the structured 500 "Git not available." error rather than a raw TypeError.

Written by the indexing model from the issue text.

Description

Did you clear cache before opening an issue?
  • I have cleared my cache
Is there an existing issue for this?
  • I have searched the existing open and closed issues
Does the issue happen when logged in?

N/A

Does the issue happen when logged out?

N/A (backend source bug)

Does the issue happen in incognito mode when logged in?

N/A

Does the issue happen in incognito mode when logged out?

N/A

Issue details

Current Behavior

In backend/src/dal/new-quotes.ts, git is initialized via tryCatchSync at module load:

// new-quotes.ts:33-35
const { data: git, error } = tryCatchSync(() =>
  simpleGit(path.join(__dirname, PATH_TO_REPO)),
);

On failure this yields data === undefined (which add() checks correctly):

// new-quotes.ts:59
if (git === undefined) throw new MonkeyError(500, "Git not available.");

But approve() checks against null instead, making the guard dead code:

// new-quotes.ts:150
if (git === null) throw new MonkeyError(500, "Git not available.");

If git initialization failed at import time, the check passes, execution reaches line 181 (await git.pull("upstream", "master")) and crashes with a raw TypeError: Cannot read properties of undefined instead of the intended structured 500 MonkeyError.

Expected Behavior

Line 150 should mirror line 59:

if (git === undefined) throw new MonkeyError(500, "Git not available.");
Steps To Reproduce
  1. Deploy the backend where simpleGit(...) init throws (e.g. repo path unavailable).
  2. Approve a quote as a quote moderator.
  3. Endpoint responds with an unhandled TypeError rather than the expected 500 "Git not available." error shape.
Environment
  • Backend, master @ 91bd24bb8
Dominant language
TypeScript
Stars
20.7k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from monkeytypegame/monkeytype

All issues in monkeytypegame/monkeytype

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.