Skip to content

refine: Refine error#83

Merged
junyu0312 merged 1 commit intomainfrom
refine
Feb 28, 2026
Merged

refine: Refine error#83
junyu0312 merged 1 commit intomainfrom
refine

Conversation

@junyu0312
Copy link
Owner

@junyu0312 junyu0312 commented Feb 28, 2026

Summary by CodeRabbit

  • Refactor
    • Standardized error handling across virtual machine architecture implementations by adopting a centralized error type.
    • Added support for hypervisor-specific error variants to improve error reporting consistency.
    • Updated error handling across ARM, x86-64, and hypervisor virtualization backends to use unified error mechanisms.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d28b54f and ef38c46.

📒 Files selected for processing (8)
  • crates/vm-core/src/arch/aarch64/vcpu.rs
  • crates/vm-core/src/arch/aarch64/vcpu/reg/esr_el2.rs
  • crates/vm-core/src/arch/vcpu.rs
  • crates/vm-core/src/arch/x86_64/vcpu.rs
  • crates/vm-core/src/error.rs
  • crates/vm-core/src/virt/hvp/vcpu.rs
  • crates/vm-core/src/virt/kvm/vcpu/arch/aarch64.rs
  • crates/vm-core/src/virt/kvm/vcpu/arch/x86_64.rs

📝 Walkthrough

Walkthrough

This pull request systematically migrates error handling across the VM core from anyhow::Result to a crate-specific crate::error::Result type. It extends the error module with new variants (KvmError, ApplevisorError, Unknown) and their corresponding From implementations, then updates method signatures across VCPU trait definitions and implementations for both AArch64 and x86_64 architectures.

Changes

Cohort / File(s) Summary
Error Type System
crates/vm-core/src/error.rs
Added three new error variants: KvmError (conditional on feature = "kvm"), ApplevisorError (conditional on feature = "hvp"), and Unknown(String). Implemented From conversions for hypervisor error types to enable ergonomic error mapping.
Core VCPU Trait Definitions
crates/vm-core/src/arch/aarch64/vcpu.rs, crates/vm-core/src/arch/x86_64/vcpu.rs, crates/vm-core/src/arch/vcpu.rs
Updated trait method return types from anyhow::Result<T> to crate::error::Result<T> across AArch64Vcpu, X86Vcpu, and Vcpu traits. Includes register accessors and SMC-related methods on AArch64 (get_smc_function_id, set_smc_return_value, etc.).
Architecture Register Handling
crates/vm-core/src/arch/aarch64/vcpu/reg/esr_el2.rs
Updated ec() method return type from anyhow::Result<Ec> to crate::error::Result<Ec> and replaced anyhow!() with Error::Unknown() for error construction.
KVM VCPU Implementations
crates/vm-core/src/virt/kvm/vcpu/arch/aarch64.rs, crates/vm-core/src/virt/kvm/vcpu/arch/x86_64.rs
Replaced all anyhow::Result with crate::error::Result in method signatures. In x86_64, expanded init_arch_vcpu() to perform CPUID mutations (bitwise OR on ecx for function 0x1) and invoke set_guest_debug() with debug flags.
HVP VCPU Implementation
crates/vm-core/src/virt/hvp/vcpu.rs
Updated method signatures for AArch64Vcpu and Vcpu trait implementations from anyhow::Result to crate::error::Result, maintaining existing functional logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • feat: Support smp #77: Updates AArch64 VCPU SMCCC methods and general vCPU APIs to use the new error type, directly touching methods modified in this PR.
  • refine: Refine Error #81: Performs crate-wide error type refactoring (renaming/defining Error and Result), closely aligned with this PR's error handling consolidation.
  • feat: Refine API for smp #76: Modifies vCPU API run method signatures; this PR's updates to the Vcpu::run return type are part of the same broader API contract changes.

Poem

🐰✨ From anyhow to clarity we hop,
Error types unified, no need to stop!
VCPU traits now speak as one,
Refactored paths—our work is done!
Thump, thump! The type system's spun. 🎯

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'refine: Refine error' is too vague and generic. It uses non-descriptive terms that don't clearly convey what error-related changes were made across the codebase. Consider a more specific title like 'Replace anyhow::Result with custom error type across VCPU implementations' or 'Migrate error handling to crate::error::Result in VM core'
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refine

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

@junyu0312 junyu0312 merged commit ce1a9bf into main Feb 28, 2026
8 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