Skip to content

improve error handling around disk partitioning#430

Open
mkocher wants to merge 1 commit into
mainfrom
mk/feat/windows-disk-handling
Open

improve error handling around disk partitioning#430
mkocher wants to merge 1 commit into
mainfrom
mk/feat/windows-disk-handling

Conversation

@mkocher
Copy link
Copy Markdown
Member

@mkocher mkocher commented May 15, 2026

The test cleanup code was trying to unmount c:, this should catch the actual failure instead of falling through to the cleanup code.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

Walkthrough

This PR adds retry and polling logic to the AssignDriveLetter method in the Windows disk partitioner. The method now makes up to 10 attempts to retrieve a valid drive letter after adding an access path, with configurable delays between polls via a new DriveLetterPollInterval field (defaulting to 1 second). The implementation strips null characters from PowerShell output before validation and returns clearer errors if assignment fails after all retries. Unit tests verify both successful retry scenarios and exhausted-retry failure paths. Integration tests add assertions to validate that disk shrinking completes successfully and that assigned drive letters are never the system partition.

Suggested reviewers

  • aramprice
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'improve error handling around disk partitioning' accurately reflects the main changes across the PR, which add assertions and retry logic with better error handling for disk operations.
Description check ✅ Passed The description is related to the changeset, specifically addressing the cleanup code issue and failure detection that is reflected in the test modifications in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mk/feat/windows-disk-handling

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@platform/windows/disk/partitioner_test.go`:
- Line 283: The failing line uses goimports-incompatible formatting; run
goimports on platform/windows/disk/partitioner_test.go (or the whole repo) and
commit the formatted file so the line with cmdRunner.AddCmdResult(getKey,
fakes.FakeCmdResult{Stdout: "E\n"}) conforms to goimports rules—this will fix
import grouping/formatting and unblock CI; locate the call by searching for
AddCmdResult, getKey, or fakes.FakeCmdResult to confirm the change.

In `@platform/windows/disk/partitioner.go`:
- Around line 174-193: The retry loop in GetDriveLetter (the for attempt := 0;
attempt < 10; attempt++ block using p.ps with driveScript) always calls
time.Sleep(pollInterval) even after the final attempt; modify the loop so it
only sleeps between attempts (e.g., compute maxAttempts := 10 or use attempt <
9) and call time.Sleep(pollInterval) only when attempt < maxAttempts-1, leaving
the error return path (which uses partitionNumber and diskNumber) unchanged.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d9a1c89b-c08a-454b-b674-b14e6c7a4136

📥 Commits

Reviewing files that changed from the base of the PR and between 02f8465 and 79286a7.

📒 Files selected for processing (4)
  • integration/windows/environment_test.go
  • integration/windows/ephemeral_disk_test.go
  • platform/windows/disk/partitioner.go
  • platform/windows/disk/partitioner_test.go


cmdRunner.AddCmdResult(addKey, fakes.FakeCmdResult{})
cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "\x00\n"}) // null char — unassigned
cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "E\n"}) // assigned on second poll
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix goimports formatting at this line to unblock lint.

CI is currently failing goimports on this line; please run goimports on the file and commit the formatted result.

Likely formatting-only adjustment
-			cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "E\n"})   // assigned on second poll
+			cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "E\n"}) // assigned on second poll
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "E\n"}) // assigned on second poll
cmdRunner.AddCmdResult(getKey, fakes.FakeCmdResult{Stdout: "E\n"}) // assigned on second poll
🧰 Tools
🪛 GitHub Check: lint (macos-latest)

[failure] 283-283:
File is not properly formatted (goimports)

🪛 GitHub Check: lint (ubuntu-latest)

[failure] 283-283:
File is not properly formatted (goimports)

🤖 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 `@platform/windows/disk/partitioner_test.go` at line 283, The failing line uses
goimports-incompatible formatting; run goimports on
platform/windows/disk/partitioner_test.go (or the whole repo) and commit the
formatted file so the line with cmdRunner.AddCmdResult(getKey,
fakes.FakeCmdResult{Stdout: "E\n"}) conforms to goimports rules—this will fix
import grouping/formatting and unblock CI; locate the call by searching for
AddCmdResult, getKey, or fakes.FakeCmdResult to confirm the change.

Comment on lines +174 to +193
for attempt := 0; attempt < 10; attempt++ {
stdout, _, _, err := p.ps(driveScript)
if err != nil {
return "", fmt.Errorf(
"failed to find drive letter for partition %s on disk %s: %s",
partitionNumber,
diskNumber,
err,
)
}

// The DriveLetter property is a char; an unassigned partition returns the null
// character (\x00). Strip it along with whitespace before checking.
letter := strings.Trim(strings.TrimSpace(stdout), "\x00")
if letter != "" {
return letter, nil
}

time.Sleep(pollInterval)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid sleeping after the last retry attempt.

The loop sleeps even on the final failed attempt, adding an unnecessary delay before returning the error.

Proposed fix
 	for attempt := 0; attempt < 10; attempt++ {
 		stdout, _, _, err := p.ps(driveScript)
 		if err != nil {
 			return "", fmt.Errorf(
 				"failed to find drive letter for partition %s on disk %s: %s",
 				partitionNumber,
 				diskNumber,
 				err,
 			)
 		}

 		// The DriveLetter property is a char; an unassigned partition returns the null
 		// character (\x00). Strip it along with whitespace before checking.
 		letter := strings.Trim(strings.TrimSpace(stdout), "\x00")
 		if letter != "" {
 			return letter, nil
 		}

-		time.Sleep(pollInterval)
+		if attempt < 9 {
+			time.Sleep(pollInterval)
+		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for attempt := 0; attempt < 10; attempt++ {
stdout, _, _, err := p.ps(driveScript)
if err != nil {
return "", fmt.Errorf(
"failed to find drive letter for partition %s on disk %s: %s",
partitionNumber,
diskNumber,
err,
)
}
// The DriveLetter property is a char; an unassigned partition returns the null
// character (\x00). Strip it along with whitespace before checking.
letter := strings.Trim(strings.TrimSpace(stdout), "\x00")
if letter != "" {
return letter, nil
}
time.Sleep(pollInterval)
}
for attempt := 0; attempt < 10; attempt++ {
stdout, _, _, err := p.ps(driveScript)
if err != nil {
return "", fmt.Errorf(
"failed to find drive letter for partition %s on disk %s: %s",
partitionNumber,
diskNumber,
err,
)
}
// The DriveLetter property is a char; an unassigned partition returns the null
// character (\x00). Strip it along with whitespace before checking.
letter := strings.Trim(strings.TrimSpace(stdout), "\x00")
if letter != "" {
return letter, nil
}
if attempt < 9 {
time.Sleep(pollInterval)
}
}
🤖 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 `@platform/windows/disk/partitioner.go` around lines 174 - 193, The retry loop
in GetDriveLetter (the for attempt := 0; attempt < 10; attempt++ block using
p.ps with driveScript) always calls time.Sleep(pollInterval) even after the
final attempt; modify the loop so it only sleeps between attempts (e.g., compute
maxAttempts := 10 or use attempt < 9) and call time.Sleep(pollInterval) only
when attempt < maxAttempts-1, leaving the error return path (which uses
partitionNumber and diskNumber) unchanged.

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

Labels

None yet

Projects

Status: Waiting for Changes | Open for Contribution

Development

Successfully merging this pull request may close these issues.

1 participant