Skip to content

Commit 66bcd5c

Browse files
authored
fix: inconsistency in /save and /load behavior with regard to file extensions (#289)
1 parent fe0db04 commit 66bcd5c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

crates/chat-cli/src/cli/chat/cli/persist.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,23 @@ impl PersistSubcommand {
7676
)?;
7777
},
7878
Self::Load { path } => {
79-
let contents = tri!(os.fs.read_to_string(&path).await, "import from", &path);
79+
// Try the original path first
80+
let original_result = ctx.fs.read_to_string(&path).await;
81+
82+
// If the original path fails and doesn't end with .json, try with .json appended
83+
let contents = if original_result.is_err() && !path.ends_with(".json") {
84+
let json_path = format!("{}.json", path);
85+
match ctx.fs.read_to_string(&json_path).await {
86+
Ok(content) => content,
87+
Err(_) => {
88+
// If both paths fail, return the original error for better user experience
89+
tri!(original_result, "import from", &path)
90+
},
91+
}
92+
} else {
93+
tri!(original_result, "import from", &path)
94+
};
95+
8096
let mut new_state: ConversationState = tri!(serde_json::from_str(&contents), "import from", &path);
8197
new_state.reload_serialized_state(os).await;
8298
session.conversation = new_state;

0 commit comments

Comments
 (0)