Skip to content

Conversation

wmmc88
Copy link
Collaborator

@wmmc88 wmmc88 commented Aug 25, 2025

This pull request introduces a new, dedicated error type for I/O operations in the wdk-build crate, providing richer context for filesystem errors. The changes refactor the codebase to use this new error type (IoError and IoErrorMetadata) throughout, improving error reporting and debugging. Additionally, all filesystem operations that can fail now capture and propagate detailed path metadata, enhancing traceability.

Error handling improvements:

  • Introduced IoError and IoErrorMetadata types in lib.rs to wrap std::io::Error with detailed path context, and updated ConfigError and related APIs to use them for all I/O error cases. [1] [2]
  • Refactored all filesystem operations (e.g., canonicalize, copy, create_dir, symlink_file, read_link, read_dir) in cargo_make.rs, lib.rs, utils.rs, and build.rs to use the new error types, ensuring errors now include relevant path metadata. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]

API and codebase consistency:

  • Updated function signatures and error conversions across the codebase to propagate IoError and IoErrorMetadata instead of raw std::io::Error, ensuring consistent error handling. [1] [2] [3]
  • Adjusted error handling in header file lookup and related utilities to leverage the new error types, improving diagnostics for missing files.

These changes significantly improve the observability and maintainability of error handling in the build system, especially for filesystem-related failures.

@wmmc88 wmmc88 changed the title Adopt IoError with metadata and optimize path creation in wdk-sys build.rs feat: enhance error handling with IoError and IoErrorMetadata for improved std::io::Error diagnostics for fs errors Aug 26, 2025
@Copilot Copilot AI review requested due to automatic review settings September 12, 2025 03:56
Copy link
Contributor

@Copilot 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 pull request enhances error handling in the wdk-build crate by introducing dedicated IoError and IoErrorMetadata types for I/O operations, providing better context for filesystem-related failures.

  • Introduces new error types (IoError and IoErrorMetadata) to wrap std::io::Error with detailed path context
  • Refactors all filesystem operations throughout the codebase to use these enhanced error types
  • Updates error handling in binding generation and file operations to capture and propagate path metadata

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
crates/wdk-sys/build.rs Updates bindgen file generation to use IoError with path metadata for write operations
crates/wdk-build/src/utils.rs Converts filesystem operations to use IoError with path context for directory reading
crates/wdk-build/src/lib.rs Defines new error types and refactors include/library path validation to use enhanced error handling
crates/wdk-build/src/cargo_make.rs Updates path resolution and file operations to use IoError with detailed path metadata

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -557,7 +594,7 @@ impl Config {
// Based off of logic from WindowsDriver.KernelMode.props &
// WindowsDriver.UserMode.props in NI(22H2) WDK
let windows_sdk_library_path = self.sdk_library_path(sdk_version)?;
library_paths.push(absolute(&windows_sdk_library_path)?);
Self::validate_and_add_include_path(&mut library_paths, &windows_sdk_library_path)?;
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The function validate_and_add_include_path is being used to validate library paths, but based on its name and implementation, it's designed for include paths. This could lead to confusion and incorrect error messages that reference 'include paths' when dealing with library paths.

Copilot uses AI. Check for mistakes.

});
}
library_paths.push(absolute(&kmdf_library_path)?);
Self::validate_and_add_include_path(&mut library_paths, &kmdf_library_path)?;
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The function validate_and_add_include_path is being used to validate library paths, but based on its name and implementation, it's designed for include paths. This could lead to confusion and incorrect error messages that reference 'include paths' when dealing with library paths.

Copilot uses AI. Check for mistakes.

});
}
library_paths.push(absolute(&umdf_library_path)?);
Self::validate_and_add_include_path(&mut library_paths, &umdf_library_path)?;
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The function validate_and_add_include_path is being used to validate library paths, but based on its name and implementation, it's designed for include paths. This could lead to confusion and incorrect error messages that reference 'include paths' when dealing with library paths.

Copilot uses AI. Check for mistakes.

@@ -1198,8 +1225,7 @@ impl Config {
fn ucx_header(&self) -> Result<String, ConfigError> {
let sdk_version = utils::detect_windows_sdk_version(&self.wdk_content_root)?;
let ucx_header_root_dir = self.sdk_library_path(sdk_version)?.join("ucx");
let max_version = utils::find_max_version_in_directory(&ucx_header_root_dir)
.map_err(|e| ConfigError::HeaderNotFound("ucxclass.h".into(), e))?;
let max_version = utils::find_max_version_in_directory(&ucx_header_root_dir)?;
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The error handling for find_max_version_in_directory has been simplified, but this removes the specific context that this is looking for the 'ucxclass.h' header file. The original error provided better diagnostics for header file lookup failures.

Copilot uses AI. Check for mistakes.

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