Skip to content

Non-repository project logs a full stack trace at error level on every git poll #513

Description

@Temikus

TL;DR: toHttpError() logs every git error at error level with a full stack trace before classifying it. Opening a project directory that is not a git repository is an expected user state, but each UI poll emits a multi-line trace for it.

Seen on v0.3.3. The path looks unchanged on main as of 9abf40b.

Detail

server/git/git-service.ts

toHttpError(error: unknown): Response {
  logger.error('[git]', error);
  if (error instanceof GitDomainError) {
    return gitDomainErrorToResponse(error);
  }
  return classifiedGitErrorToResponse(classifyGitError(error));
},

The log call happens unconditionally, ahead of the classification that follows it. When the open project path is not a repository, assertGitRepository() throws, and the UI's periodic getRemoteStatus() and getTargetCandidates() polls each produce:

[git:git-service] [git] 266 |       projectPath,
267 |       ['rev-parse', '--is-inside-work-tree'],
268 |       readOnlyGitOptions(),
269 |     ));
270 |   } catch {
271 |     throw new Error('Git is not initialized in this directory. Initialize a repository with "git init" before using source control actions.');
                    ^
error: Git is not initialized in this directory. Initialize a repository with "git init" before using source control actions.
      at assertGitRepository (/app/server/git/run.ts:271:15)
      at async getRemoteStatus (/app/server/git/status.ts:521:11)

This repeats for as long as the project stays open, so a user who has simply not run git init yet generates continuous error-level output.

Suggested fix

Classify first, then log at a level matching the classification: debug for expected conditions such as a non-repository path, with error reserved for genuine faults. classifyGitError() and GitDomainError already carry the information needed to make that call.

Same theme as #512, different code path.

Happy to send a PR if useful. Thanks for garcon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions