Skip to content

fix: readConfig now logs errors and backs up corrupted config#469

Open
HiddenPuppy wants to merge 1 commit intomainfrom
fix/issue-384
Open

fix: readConfig now logs errors and backs up corrupted config#469
HiddenPuppy wants to merge 1 commit intomainfrom
fix/issue-384

Conversation

@HiddenPuppy
Copy link
Copy Markdown
Collaborator

Summary

readConfig() had a bare catch {} that silently returned null on any parse/decrypt error, causing user config to disappear without trace.

Changes

  • Log error: added console.error('[config] failed to read:', err) in the catch block
  • Backup corrupted file: renamed config.jsonconfig.json.corrupted-<ISO timestamp> so recovery is possible
  • Graceful fallback: still returns null so the first-run/onboarding flow kicks in as expected

Testing

  • pnpm check ✅ (architecture guardrails passed, eslint + prettier clean)
  • pnpm test ✅ (256 tests, 42 test files — all passing)

Fixes #384

- Log parse/read errors via console.error
- Rename corrupted config file with .corrupted-<timestamp> suffix
- Keep returning null so first-run flow still kicks in

Fixes #384
@HiddenPuppy HiddenPuppy requested a review from samzong as a code owner April 28, 2026 02:38
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the robustness of the configuration loading process by replacing a silent failure with explicit error logging and a backup strategy for corrupted files. These changes ensure that users are aware of configuration issues while preserving the original state of the file for potential recovery, without disrupting the application's fallback behavior.

Highlights

  • Error Logging: Added console logging for configuration read errors to improve debuggability.
  • Configuration Backup: Implemented a mechanism to rename corrupted configuration files with an ISO timestamp, ensuring data can be recovered if needed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

Hi @HiddenPuppy,
Thanks for your pull request!
If the PR is ready, use the /auto-cc command to assign Reviewer to Review.
We will review it shortly.

Details

Instructions for interacting with me using comments are available here.
If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the configuration reading logic in the Electron main process to log errors and attempt to back up corrupted configuration files by renaming them with a timestamped suffix. A review comment suggests refining this behavior to only trigger the backup rename when a SyntaxError is encountered, preventing data loss from transient I/O or permission errors that do not necessarily indicate file corruption.

Comment on lines +164 to 173
} catch (err) {
console.error('[config] failed to read:', err);
const corruptedPath = `${cfgPath}.corrupted-${new Date().toISOString().replace(/[:.]/g, '-')}`;
try {
renameSync(cfgPath, corruptedPath);
} catch {
// best-effort backup rename
}
return null;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation renames the configuration file as 'corrupted' for any error encountered during the read or migration process. This is quite aggressive and could lead to unnecessary data loss. For example, if an I/O error occurs during migration (like a full disk) or if there's a transient filesystem permission issue, the user's valid configuration will be moved aside, forcing them to reconfigure the app from scratch. It is safer to only perform the backup rename if the error is a SyntaxError, which specifically indicates that the file content is not valid JSON and thus truly corrupted.

  } catch (err) {
    console.error('[config] failed to read:', err);
    if (err instanceof SyntaxError) {
      const corruptedPath = cfgPath + '.corrupted-' + new Date().toISOString().replace(/[:.]/g, '-');
      try {
        renameSync(cfgPath, corruptedPath);
      } catch {
        // best-effort backup rename
      }
    }
    return null;
  }

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.

[Bug] readConfig silently returns null on parse errors, losing user config

1 participant