Skip to content

Conversation

jeckersb
Copy link
Collaborator

This appears to have been accidentally added somewhere along the way,
and I would like to use these in composefs-boot.

Signed-off-by: John Eckersberg [email protected]

This appears to have been accidentally added somewhere along the way,
and I would like to use these in composefs-boot.

Signed-off-by: John Eckersberg <[email protected]>
@jeckersb jeckersb force-pushed the untest-require_value branch from d7a9149 to f83c655 Compare August 27, 2025 20:39
@jeckersb jeckersb changed the title kernel_cmdline: remove cfg(test) for require_value_* methods` kernel_cmdline: remove cfg(test) for require_value_* methods Aug 27, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request makes the require_value_of and require_value_of_utf8 methods public by removing their #[cfg(test)] attributes. The change is correct and achieves its goal. My review includes suggestions to improve these newly-public functions by making their error handling more specific and enhancing their documentation. Since the functions are now part of the crate's public API, these improvements would increase robustness and usability for consumers.

@@ -106,7 +106,6 @@ impl<'a> Cmdline<'a> {
/// Find the value of the kernel argument with the provided name, which must be present.
///
/// Otherwise the same as [`Self::value_of`].
#[cfg(test)]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

By removing this attribute, require_value_of becomes part of the public API. While this is the goal of the PR, the function's implementation could be improved for public use. The error message when a value isn't found is ambiguous; it doesn't distinguish between a missing key and a key that exists but has no value (a switch). For a robust public API, providing distinct errors for these cases is a best practice.

I recommend refactoring the function to use self.find() and then checking for the presence of a value to provide more specific error messages. Additionally, the documentation should be updated with an # Errors section to clearly describe the error conditions, as recommended by Rust API guidelines.

@@ -118,7 +117,6 @@ impl<'a> Cmdline<'a> {
/// Find the value of the kernel argument with the provided name, which must be present.
///
/// Otherwise the same as [`Self::value_of`].
#[cfg(test)]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to require_value_of, by removing this attribute, require_value_of_utf8 is now exposed as a public API. It shares the same issue with an ambiguous error message when a value is not found. It would be beneficial to refactor it to provide a clearer error when a key is present but has no value, versus when the key is missing entirely. This will make the API more robust and easier to use for developers consuming this crate.

@jeckersb jeckersb marked this pull request as draft August 27, 2025 21:10
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.

2 participants