Skip to content

Commit b2b1604

Browse files
ansasakiclaude
andcommitted
keylimectl: Use correct variant for UEFI log parse failures
The measured boot policy generator was using PolicyGenerationError::Output (which formats as "Failed to write output to ...") when the UEFI event log could not be read or parsed. This produced misleading error messages like "Failed to write output to /sys/kernel/.../binary_bios_measurements" for what is actually a read/parse error. Add a dedicated EventLogParse variant and use it in generate_from_eventlog() and get_eventlog_stats(), producing clear messages like "Failed to parse event log /sys/.../binary_bios_measurements: IO error: No such file". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
1 parent e0dde57 commit b2b1604

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

keylimectl/src/commands/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ pub enum PolicyGenerationError {
156156
#[error("Unsupported hash algorithm: {algorithm}")]
157157
UnsupportedAlgorithm { algorithm: String },
158158

159+
/// Event log parse error
160+
#[error("Failed to parse event log {path}: {reason}")]
161+
EventLogParse { path: PathBuf, reason: String },
162+
159163
/// Output write error
160164
#[error("Failed to write output to {path}: {reason}")]
161165
Output { path: PathBuf, reason: String },

keylimectl/src/policy_tools/measured_boot_gen.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ pub fn generate_from_eventlog(
2121
path: &Path,
2222
include_secureboot: bool,
2323
) -> Result<MeasuredBootPolicy, PolicyGenerationError> {
24-
let path_str =
25-
path.to_str().ok_or_else(|| PolicyGenerationError::Output {
24+
let path_str = path.to_str().ok_or_else(|| {
25+
PolicyGenerationError::EventLogParse {
2626
path: path.to_path_buf(),
2727
reason: "Invalid path encoding".to_string(),
28-
})?;
28+
}
29+
})?;
2930

3031
let handler = UefiLogHandler::new(path_str).map_err(|e| {
31-
PolicyGenerationError::Output {
32+
PolicyGenerationError::EventLogParse {
3233
path: path.to_path_buf(),
33-
reason: format!("Failed to parse UEFI event log: {e}"),
34+
reason: format!("{e}"),
3435
}
3536
})?;
3637

@@ -363,16 +364,17 @@ pub struct MeasuredBootStats {
363364
pub fn get_eventlog_stats(
364365
path: &Path,
365366
) -> Result<MeasuredBootStats, PolicyGenerationError> {
366-
let path_str =
367-
path.to_str().ok_or_else(|| PolicyGenerationError::Output {
367+
let path_str = path.to_str().ok_or_else(|| {
368+
PolicyGenerationError::EventLogParse {
368369
path: path.to_path_buf(),
369370
reason: "Invalid path encoding".to_string(),
370-
})?;
371+
}
372+
})?;
371373

372374
let handler = UefiLogHandler::new(path_str).map_err(|e| {
373-
PolicyGenerationError::Output {
375+
PolicyGenerationError::EventLogParse {
374376
path: path.to_path_buf(),
375-
reason: format!("Failed to parse UEFI event log: {e}"),
377+
reason: format!("{e}"),
376378
}
377379
})?;
378380

0 commit comments

Comments
 (0)