Skip to content

Conversation

@cnaples79
Copy link

Summary

Provides a more helpful error message when the /etc/sudoers file is not found, making it clearer to users what went wrong and how to fix it.

Changes Made

Modified src/sudo/pipeline.rs:read_sudoers() to detect when Sudoers::open() fails with ErrorKind::NotFound and provide a detailed, actionable error message instead of the generic "file not found" error.

Before

No such file or directory (os error 2)

After

sudoers file not found: /etc/sudoers

The sudoers file is required for sudo-rs to function. Please ensure:
- The file exists at the expected location
- You have the necessary permissions to read it
- If setting up sudo-rs for the first time, create a sudoers file with appropriate permissions

For more information, see the sudo-rs documentation.

Rationale

As discussed in #1306, when /etc/sudoers is missing, users currently see an unhelpful "file not found" error that doesn't explain:

  • What file is missing
  • Why it's needed
  • How to fix the problem

This improved error message addresses all three points, making it much easier for users (especially those installing from tarballs on clean systems) to understand and resolve the issue.

Implementation Details

  • Added check for io::ErrorKind::NotFound in the error mapping
  • Follows similar pattern to the existing error improvement for included sudoers files (lines 717-722 in src/sudoers/mod.rs)
  • Does not change behavior, only improves error messaging
  • No additional dependencies or complexity introduced

Testing

  • Error handling path is triggered when sudoers file doesn't exist
  • Maintains backward compatibility with all other error types

Fixes #1306

When the sudoers file is not found, provide a more helpful error message
that explains the issue and suggests possible solutions, rather than just
showing a generic file not found error.

The new error message includes:
- The exact path that was attempted
- Explanation that the file is required
- Suggestions for resolution:
  - Verify file exists at expected location
  - Check read permissions
  - Create file if setting up for first time
- Reference to documentation for more help

This addresses the confusion users experience when encountering a missing
sudoers file, making it clearer what went wrong and how to fix it.

Fixes trifectatechfoundation#1306
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.

Handle missing /etc/sudoers with grace

1 participant