Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion crates/goose/src/config/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, RwLock};
use tracing;
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

Import the tracing macro directly instead of the module. Change use tracing; to use tracing::error; to match the idiomatic Rust pattern used throughout the codebase. This allows using error!() instead of tracing::error!().

Suggested change
use tracing;
use tracing::error;

Copilot uses AI. Check for mistakes.
use utoipa::ToSchema;

const PERMISSION_FILE: &str = "permission.yaml";
Expand Down Expand Up @@ -45,7 +46,17 @@ impl PermissionManager {
let permission_map = if permission_path.exists() {
let file_contents =
fs::read_to_string(&permission_path).expect("Failed to read permission.yaml");
serde_yaml::from_str(&file_contents).unwrap_or_else(|_| HashMap::new())
serde_yaml::from_str(&file_contents).unwrap_or_else(|e| {
tracing::error!(
"Failed to parse {}: {}. Refusing to start with corrupted permission config.",
permission_path.display(),
e,
);
panic!(
"Corrupted permission config at {}. Fix or remove the file to continue.",
permission_path.display(),
);
})
} else {
// Consolidate directory creation for re-use in global singleton or ACP.
fs::create_dir_all(&config_dir).expect("Failed to create config directory");
Expand Down Expand Up @@ -293,4 +304,13 @@ mod tests {
.always_allow
.contains(&"nonprefix__tool2".to_string()));
}

#[test]
#[should_panic(expected = "Corrupted permission config")]
fn test_corrupted_permission_file_panics() {
let temp_dir = TempDir::new().unwrap();
let permission_path = temp_dir.path().join(PERMISSION_FILE);
fs::write(&permission_path, "{{invalid yaml: [broken").unwrap();
PermissionManager::new(temp_dir.path().to_path_buf());
}
}
Loading