Skip to content

Conversation

@zvonkok
Copy link
Collaborator

@zvonkok zvonkok commented Jan 15, 2026

Remove anyhow dependency and introduce a minimal ResultExt trait with .or_panic(impl Display) method. This enables fail-fast semantics with format_args!() for zero-allocation error messages, better suited for a minimal init process.

  • Add ResultExt trait in macros.rs with #[cold]/#[inline(never)] for optimized error paths
  • Update execute.rs, syslog.rs to use .or_panic(format_args!(...))
  • Add set_test_panic_hook() in kata_agent tests to ensure forked children exit non-zero on panic (Rust test harness catches panics)

Copilot AI review requested due to automatic review settings January 15, 2026 23:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the codebase to remove the anyhow dependency and replace it with a custom ResultExt trait for zero-allocation error handling. The changes align with the minimal init process requirements where fail-fast semantics via panics are more appropriate than error propagation.

Changes:

  • Removed anyhow dependency from Cargo.toml and Cargo.lock
  • Added ResultExt trait in macros.rs with .or_panic(impl Display) method using #[cold] and #[inline(never)] attributes for optimized error paths
  • Converted all functions returning Result<T> to either return T directly or return nothing (unit type), panicking on errors
  • Updated all tests to use panic::catch_unwind() to verify panic behavior instead of checking for Err results
  • Added set_test_panic_hook() helper in kata_agent tests to ensure forked children exit with non-zero status on panic

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/macros.rs Replaced must! macro with ResultExt trait providing .or_panic() method with zero-allocation error formatting
src/execute.rs Updated foreground() and background() to panic on errors using .or_panic(format_args!(...))
src/syslog.rs Changed poll() to panic on errors instead of returning Result
src/main.rs Removed must! macro calls, functions now panic directly; added public export of ResultExt
src/toolkit.rs Updated ctk() and nvidia_ctk_cdi() to panic instead of returning Result
src/smi.rs Updated all nvidia-smi functions to panic on errors instead of returning Result
src/nvrc.rs Changed check_daemons() to panic directly instead of returning Result
src/mount.rs Updated all mount functions to panic using unwrap_or_else instead of returning Result
src/modprobe.rs Changed load() to panic on errors instead of returning Result
src/kernel_params.rs Updated parameter parsing functions to use .expect() instead of returning Result
src/kata_agent.rs Updated kata-agent functions to panic on errors; added set_test_panic_hook() for forked test children
src/daemon.rs Updated daemon spawning functions to panic on errors instead of returning Result
src/lockdown.rs Changed set_panic_hook() and disable_modules_loading() to panic on errors
src/kmsg.rs Updated kernlog_setup() and kmsg() functions to panic on errors
Cargo.toml Removed anyhow dependency
Cargo.lock Removed anyhow dependency and its entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ion error handling

Remove anyhow dependency and introduce a minimal ResultExt trait with
.or_panic(impl Display) method. This enables fail-fast semantics with
format_args!() for zero-allocation error messages, better suited for
a minimal init process.

- Add ResultExt trait in macros.rs with #[cold]/#[inline(never)] for
  optimized error paths
- Update execute.rs, syslog.rs to use .or_panic(format_args!(...))
- Add set_test_panic_hook() in kata_agent tests to ensure forked
  children exit non-zero on panic (Rust test harness catches panics)

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
@zvonkok zvonkok added the ok-to-test Ok to test label Jan 16, 2026
@zvonkok zvonkok merged commit 95f7915 into NVIDIA:main Jan 16, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Ok to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant