Skip to content

Commit 533bfaf

Browse files
authored
fix: search_extension should not panic when ext is not found (#983)
This commit fixes a bug that the search_extension() function panics when the "GET /store/_search" interface returns a 404 response. ``` GET /store/_search?query=<query string> {"_id":"_search","result":"not_found"} ``` It also improves the panic message by including varaible "response" in it, so that we can inspect the actual response. ``` let hits_json = response.remove("hits").unwrap_or_else(|| { panic!( "the JSON response should contain field [hits], response [{:?}]", response ) }); ```
1 parent 459705a commit 533bfaf

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

  • docs/content.en/docs/release-notes
  • src-tauri/src/extension/third_party/install

docs/content.en/docs/release-notes/_index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Information about release notes of Coco App is provided here.
1111
### ❌ Breaking changes
1212
### 🚀 Features
1313
### 🐛 Bug fix
14+
15+
- fix: search_extension should not panic when ext is not found #983
16+
1417
### ✈️ Improvements
1518

1619
## 0.9.0 (2025-11-19)

src-tauri/src/extension/third_party/install/store.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,23 @@ pub(crate) async fn search_extension(
104104
.await
105105
.map_err(|e| format!("Failed to send request: {:?}", e))?;
106106

107+
if response.status() == StatusCode::NOT_FOUND {
108+
return Ok(Vec::new());
109+
}
110+
107111
// The response of a ES style search request
108112
let mut response: JsonObject<String, Json> = response
109113
.json()
110114
.await
111115
.map_err(|e| format!("Failed to parse response: {:?}", e))?;
112116

113-
let hits_json = response
114-
.remove("hits")
115-
.expect("the JSON response should contain field [hits]");
117+
let hits_json = response.remove("hits").unwrap_or_else(|| {
118+
panic!(
119+
"the JSON response should contain field [hits], response [{:?}]",
120+
response
121+
)
122+
});
123+
116124
let mut hits = match hits_json {
117125
Json::Object(obj) => obj,
118126
_ => panic!(

0 commit comments

Comments
 (0)