Skip to content

feat: harden updater error handling and input validation#50

Merged
hieuck merged 1 commit into
mainfrom
feature/harden-updater-errors
Jul 8, 2026
Merged

feat: harden updater error handling and input validation#50
hieuck merged 1 commit into
mainfrom
feature/harden-updater-errors

Conversation

@hieuck

@hieuck hieuck commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary\r\nImprove input validation and error reporting in the external updater workflow to catch misconfiguration early and surface clear failures.\r\n\r\n## Changes\r\n- now validates file extensions for the plugin DLL, the update file, and the updater EXE.\r\n- Validates that the KeePass process ID is non-negative.\r\n- Validates the KeePass executable path extension when provided.\r\n- The updater now uses distinct exit codes (, , , ).\r\n- The updater validates arguments, checks source file existence, creates the destination directory if needed, and verifies the restart executable before launching it.\r\n\r\n## Tests\r\n- Added 5 unit tests for invalid inputs.\r\n- MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. passes: 71/71.\r\n\r\nCloses #46.

- Validate plugin/new-plugin/updater paths and extensions in PluginUpdater.TryScheduleUpdate.

- Validate KeePass process ID is non-negative.

- Add distinct exit codes and argument validation in KeePassAutoReload.Updater Program.cs.

- Add directory creation before copying and verify restart executable exists.

- Add 5 unit tests for invalid PluginUpdater inputs; dotnet test passes 71/71.

Closes #46.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 16 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d4eabf9-cb39-4c08-86c2-5980d285c634

📥 Commits

Reviewing files that changed from the base of the PR and between 37d3f63 and a2776fa.

📒 Files selected for processing (3)
  • src/KeePassAutoReload.Updater/Program.cs
  • src/PluginUpdater.cs
  • tests/Tests.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/harden-updater-errors

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.

Comment on lines 27 to 37

if (string.Equals(current, "--process-id", StringComparison.OrdinalIgnoreCase))
{
int.TryParse(value, out processId);
if (!int.TryParse(value, out processId) || processId < 0)
{
Console.Error.WriteLine("Invalid process ID.");
return ExitInvalidArguments;
}
}
else if (string.Equals(current, "--source", StringComparison.OrdinalIgnoreCase))
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Argument Value Validation Weakness

The argument parsing logic assumes that every flag is followed by a value, but does not check if the value is another flag (e.g., --source --destination ...). This can lead to incorrect assignments and subtle bugs if the user omits a value or provides flags in an unexpected order.

Recommendation:
Add a check to ensure that value does not start with -- before assigning it to a variable. For example:

if (value.StartsWith("--")) {
    Console.Error.WriteLine($"Missing value for argument: {current}");
    return ExitInvalidArguments;
}

Comment on lines 90 to 119

Thread.Sleep(1000);

string destinationDirectory = Path.GetDirectoryName(destination);
if (!string.IsNullOrWhiteSpace(destinationDirectory) && !Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}

File.Copy(source, destination, overwrite: true);
File.Delete(source);

if (!string.IsNullOrWhiteSpace(restart) && File.Exists(restart))
if (string.IsNullOrWhiteSpace(restart)) return ExitSuccess;

if (!File.Exists(restart))
{
Process.Start(restart);
Console.Error.WriteLine("KeePass executable not found: " + restart);
return ExitRestartFailed;
}

return 0;
Process.Start(restart);
return ExitSuccess;
}
catch (Exception ex)
{
Console.Error.WriteLine("Update failed: " + ex.Message);
return 2;
return ExitUpdateFailed;
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

File Operation Robustness and Error Handling

The file operations (File.Copy, File.Delete, Process.Start) are performed without handling specific exceptions or implementing retry logic. If the destination file is locked, or there are permission issues, the update will fail immediately. The catch-all exception handler only logs the error message, which may not provide sufficient diagnostic information.

Recommendation:

  • Implement more granular exception handling for file operations to provide clearer error messages (e.g., catch IOException, UnauthorizedAccessException).
  • Consider adding retry logic for file operations in case of transient errors (e.g., file temporarily locked).
  • Log the stack trace or more detailed error information to aid in troubleshooting.

Example:

try {
    File.Copy(source, destination, overwrite: true);
} catch (IOException ioEx) {
    Console.Error.WriteLine($"File copy failed: {ioEx.Message}");
    return ExitUpdateFailed;
}

Comment thread src/PluginUpdater.cs
Comment on lines 49 to 50
if (!File.Exists(newPluginPath)) return false;
if (!File.Exists(updaterExePath)) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Insufficient Error Reporting for File Existence Checks

The method returns false if either newPluginPath or updaterExePath does not exist, but does not indicate which file was missing. This lack of detail can hinder debugging and error reporting. Consider returning a more informative result, such as an enum or error message, to specify which file check failed.

Example improvement:

if (!File.Exists(newPluginPath)) return Result.NewPluginMissing;
if (!File.Exists(updaterExePath)) return Result.UpdaterExeMissing;

@hieuck hieuck merged commit 95ea1de into main Jul 8, 2026
2 checks passed
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