Skip to content

fix(repos): log the cause when repo create fails#103

Open
mizuki0x wants to merge 1 commit into
Gitlawb:mainfrom
mizuki0x:fix/surface-git-error-cause
Open

fix(repos): log the cause when repo create fails#103
mizuki0x wants to merge 1 commit into
Gitlawb:mainfrom
mizuki0x:fix/surface-git-error-cause

Conversation

@mizuki0x

@mizuki0x mizuki0x commented Jun 25, 2026

Copy link
Copy Markdown

What

create_repo was the one git-backed handler that mapped its error without logging it. info_refs, receive_pack, and acquire all tracing::error! with repo/service context on failure; create_repo just did .map_err(|e| AppError::Git(e.to_string()))?.

So a failed POST /api/v1/repos returns an opaque 500 {"error":"git_error","message":"initializing bare repo"} with no server-side trail to the real cause. to_string() on the anyhow::Error keeps only the outer .context(...), and nothing logs the rest, so the underlying init_bare failure (the git init stderr, a filesystem error like No space left on device, and so on) is lost.

Change

create_repo now logs the full chain on failure ({:#}, so the leaf cause is kept) with owner/repo context, matching the other git handlers. The response is unchanged, the detail goes to the logs only, not the client.

One handler, one log line. No status codes, routes, response bodies, or control flow change.

Note

This makes a failure diagnosable, it doesn't fix whatever the underlying init_bare failure is (that looked environment-specific when I hit it against a live node, the git init itself is fine). The point is the next one shows up in the logs with its cause instead of as a bare 500.

Summary by CodeRabbit

  • Bug Fixes
    • Improved repository creation error handling so setup failures are surfaced more reliably.
    • Added clearer, formatted error logging when repository initialization fails, making it easier to diagnose troubleshooting issues.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4db2bdb4-d39c-43b1-9abb-b1878210bffc

📥 Commits

Reviewing files that changed from the base of the PR and between 2f6611a and 2f71682.

📒 Files selected for processing (1)
  • crates/gitlawb-node/src/api/repos.rs

📝 Walkthrough

Walkthrough

create_repo now logs repo_store.init(...) failures with tracing::error! before converting them to AppError::Git.

Changes

Repository init error logging

Layer / File(s) Summary
Error logging in create_repo
crates/gitlawb-node/src/api/repos.rs
create_repo now logs repo_store.init(...) errors with the full cause chain before mapping them to AppError::Git.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🐇 I hopped through the logs today,
One error now has words to say.
A tiny trace, a Gitty sigh,
Then AppError scampers by.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change: adding logging for repo creation failures.
Description check ✅ Passed The description covers the bug, fix, and impact, but it omits the template's Summary, Kind of change, and verification details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/gitlawb-node/src/api/repos.rs (1)

463-473: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Now-redundant handler logging will double-log 5xx failures.

IntoResponse was updated to tracing::error! on every server-error response, but these handlers (git_info_refs, git_receive_pack, and the git_upload_pack fallback at 533-542) still emit their own tracing::error! before returning AppError::git(e). Each git failure will now produce two error lines. These local logs carry richer context (repo, service), so consider keeping them and downgrading/removing the generic log in IntoResponse, or dropping the local logs — but not both.

Also applies to: 651-668

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/gitlawb-node/src/api/repos.rs` around lines 463 - 473, The
handler-level tracing in git_info_refs, git_receive_pack, and the
git_upload_pack fallback is now duplicating the new server-error logging from
IntoResponse, so each git 5xx failure is logged twice. Decide on a single
logging layer: either keep the repo/service-specific tracing::error! calls in
these handlers and remove or downgrade the generic error log in IntoResponse, or
remove the local error logs and rely on IntoResponse, but avoid logging the same
AppError::git(e) path in both places.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/gitlawb-node/src/api/changelog.rs`:
- Line 44: Update AppError::git so client-facing error strings no longer use
expanded formatting from format!("{e:#}") and instead return the plain
user-friendly message via e.to_string() or format!("{e}"). Keep the response
body generic in the changelog API path that uses map_err(AppError::git), and if
full error details are needed, emit them only through server-side
tracing::error! while preserving AppError::git as the single place controlling
this formatting.

---

Nitpick comments:
In `@crates/gitlawb-node/src/api/repos.rs`:
- Around line 463-473: The handler-level tracing in git_info_refs,
git_receive_pack, and the git_upload_pack fallback is now duplicating the new
server-error logging from IntoResponse, so each git 5xx failure is logged twice.
Decide on a single logging layer: either keep the repo/service-specific
tracing::error! calls in these handlers and remove or downgrade the generic
error log in IntoResponse, or remove the local error logs and rely on
IntoResponse, but avoid logging the same AppError::git(e) path in both places.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c1ce05a-5770-489b-ae5e-8cd0d84cf390

📥 Commits

Reviewing files that changed from the base of the PR and between 2f6611a and 4e7da64.

📒 Files selected for processing (6)
  • crates/gitlawb-node/src/api/changelog.rs
  • crates/gitlawb-node/src/api/encrypted.rs
  • crates/gitlawb-node/src/api/issues.rs
  • crates/gitlawb-node/src/api/pulls.rs
  • crates/gitlawb-node/src/api/repos.rs
  • crates/gitlawb-node/src/error.rs

Comment thread crates/gitlawb-node/src/api/changelog.rs Outdated
create_repo was the one git handler that mapped its error without logging
it (info_refs, receive_pack, acquire all log with repo context). So a
failed init_bare returned an opaque 500 "initializing bare repo" with no
server-side trail to the real cause.

Log the full anyhow chain ({:#}, so the leaf git/filesystem error is kept)
with owner+repo context, matching the other handlers. Response unchanged.
@mizuki0x mizuki0x force-pushed the fix/surface-git-error-cause branch from 4e7da64 to 2f71682 Compare June 25, 2026 15:10
@mizuki0x mizuki0x changed the title fix(api): surface the underlying cause of git errors fix(repos): log the cause when repo create fails Jun 25, 2026
@mizuki0x

mizuki0x commented Jun 25, 2026

Copy link
Copy Markdown
Author

Both of coderabbitai's points are valid and I've addressed them by narrowing this down. Putting the full chain in the response body would leak internal detail, and the central IntoResponse log double-logged the handlers that already log with repo/service context. Dropped the helper, the response change, and the central log entirely. The PR now just adds a single tracing::error! to create_repo (the one git handler that wasn't logging its failure), so the cause lands in the logs with owner/repo context like the others, response unchanged.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@beardthelion

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@beardthelion beardthelion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Verified the diff against the sibling handlers and it does what the description says: create_repo was the only git-backed handler that mapped repo_store.init() to AppError::Git without logging the cause, and this brings it to parity. The log is server-side only and the client response is unchanged (still AppError::Git(e.to_string())), so nothing new is exposed to the caller. req.name is charset-restricted upstream and owner_did is the authenticated DID, so there's no log-injection or move/borrow issue in the closure, and init() returns anyhow::Result, so {:#} walks to the leaf cause as intended.

One non-blocking note, no change needed: this logs the full chain via format!("{e:#}") where the other git handlers (repos.rs:504/511/692/706) use plain %e. That's the better choice for an init failure; flagging only so the divergence from the siblings is deliberate.

CI is green on the current head and the earlier review points were addressed by narrowing the change.

@kevincodex1 LGTM

@beardthelion beardthelion added crate:node gitlawb-node — the serving node and REST API subsystem:api Node REST API request/response surface sev:low Cosmetic, cleanup, or nice-to-have labels Jun 25, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None. This is a clean, low-risk logging improvement that aligns create_repo with the rest of the handler error handling.

@kevincodex1 LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crate:node gitlawb-node — the serving node and REST API sev:low Cosmetic, cleanup, or nice-to-have subsystem:api Node REST API request/response surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants