Skip to content

Commit ed5dbcd

Browse files
committed
feat(plugin-tee): raise permission denied error
1 parent d1e1551 commit ed5dbcd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

crates/plugin-tee/src/lib.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,32 @@ fn run_inner(payload: String) -> Result<String, String> {
6868

6969
if !is_append {
7070
let mut file = std::fs::File::create(&filepath)
71-
.map_err(|e| format!("Failed to create file '{}': {}", filepath, e))?;
71+
.map_err(|e| enhanced_error(e, format!("Failed to create file '{}'", filepath)))?;
7272
file.write_all(content_as_bytes)
73-
.map_err(|e| format!("Failed to write to file '{}': {}", filepath, e))?;
73+
.map_err(|e| enhanced_error(e, format!("Failed to write to file '{}'", filepath)))?;
7474
return Ok(content);
7575
} else {
7676
let mut file = std::fs::File::options()
7777
.append(true)
7878
.open(&filepath)
79-
.map_err(|e| format!("Failed to open file in append mode '{}': {}", filepath, e))?;
79+
.map_err(|e| {
80+
enhanced_error(
81+
e,
82+
format!("Failed to open file in append mode '{}'", filepath),
83+
)
84+
})?;
8085
// Add a newline before the content in append mode
81-
file.write_all(b"\n")
82-
.map_err(|e| format!("Failed to write newline to file '{}': {}", filepath, e))?;
86+
file.write_all(b"\n").map_err(|e| {
87+
enhanced_error(e, format!("Failed to write newline to file '{}'", filepath))
88+
})?;
8389
file.write_all(content_as_bytes)
84-
.map_err(|e| format!("Failed to write to file '{}': {}", filepath, e))?;
90+
.map_err(|e| enhanced_error(e, format!("Failed to write to file '{}'", filepath)))?;
8591
return Ok(content);
8692
}
8793
}
8894

95+
fn enhanced_error(e: std::io::Error, more_info: String) -> String {
96+
format!("{} - {} - {}", e.kind(), more_info, e.to_string())
97+
}
98+
8999
bindings::export!(Component with_types_in bindings);

0 commit comments

Comments
 (0)