Skip to content

fix(cli): back up corrupt state/config files instead of silently resetting#8337

Open
DavidWells wants to merge 1 commit into
mainfrom
split/config-guard
Open

fix(cli): back up corrupt state/config files instead of silently resetting#8337
DavidWells wants to merge 1 commit into
mainfrom
split/config-guard

Conversation

@DavidWells

Copy link
Copy Markdown
Contributor

Split from #8300 (9 of 9).

What

A malformed .netlify/state.json or global config.json (which holds auth tokens) was silently ignored — and could be silently wiped on the next write, losing the project link or credentials with no trace. Now the corrupt file is backed up to <file>.corrupt.<mtime> with a stderr warning naming both paths and a recovery hint, then the command proceeds as before:

 ›   Warning: .netlify/state.json contains malformed JSON and will be reset.
 ›   A backup of the corrupt file was saved to .netlify/state.json.corrupt.1783361094729.
 ›   Repair and restore the backup, or delete it and re-run netlify link.

Why it helps agents

An agent that interrupts a write (or a human that hand-edits a config) shouldn't lose state invisibly. Silent resets produce confusing downstream failures ("why am I suddenly unlinked?") that are expensive to diagnose; a named backup makes the failure observable and recoverable.

Testing

  • New unit tests for the backup guard (valid, empty, missing, and corrupt files)
  • typecheck ✓ lint ✓ 411 unit tests ✓ manual smoke test of both file types ✓

…tting

A malformed .netlify/state.json or global config.json (which holds auth
tokens) was silently ignored and could be silently wiped, losing the
project link or credentials with no trace. The corrupt file is now
copied to <file>.corrupt.<mtime> with a stderr warning naming both
paths before the command proceeds.
@DavidWells DavidWells requested a review from a team as a code owner July 6, 2026 18:05
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@DavidWells, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df1f9541-3204-4bac-8cd2-4829eae5ab32

📥 Commits

Reviewing files that changed from the base of the PR and between 3c41e72 and a6b6bfe.

📒 Files selected for processing (4)
  • src/commands/base-command.ts
  • src/commands/main.ts
  • src/utils/config-guard.ts
  • tests/unit/utils/config-guard.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/config-guard

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.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📊 Benchmark results

Comparing with 3c41e72

  • Dependency count: 1,127 (no change)
  • Package size: 379 MB ⬇️ 0.00% decrease vs. 3c41e72
  • Number of ts-expect-error directives: 359 (no change)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant