fix: properly return errors for malformed config (#2027)

This commit is contained in:
Alex Hancock
2025-04-04 09:55:48 -04:00
committed by GitHub
parent e438b331fe
commit c3042067a0
6 changed files with 25 additions and 13 deletions
Generated
+4 -9
View File
@@ -2789,7 +2789,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.2",
"tower-service",
"webpki-roots 0.26.8",
"webpki-roots",
]
[[package]]
@@ -4758,6 +4758,7 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"rustls 0.21.12",
"rustls-native-certs 0.6.3",
"rustls-pemfile 1.0.4",
"serde",
"serde_json",
@@ -4773,7 +4774,6 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.25.4",
"winreg",
]
@@ -4807,6 +4807,7 @@ dependencies = [
"pin-project-lite",
"quinn",
"rustls 0.23.23",
"rustls-native-certs 0.8.1",
"rustls-pemfile 2.2.0",
"rustls-pki-types",
"serde",
@@ -4823,7 +4824,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.26.8",
"webpki-roots",
"windows-registry",
]
@@ -6551,12 +6552,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webpki-roots"
version = "0.26.8"
@@ -185,7 +185,17 @@ pub async fn get_extensions(
match ExtensionManager::get_all() {
Ok(extensions) => Ok(Json(ExtensionResponse { extensions })),
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
Err(err) => {
// Return UNPROCESSABLE_ENTITY only for DeserializeError, INTERNAL_SERVER_ERROR for everything else
if err
.downcast_ref::<goose::config::base::ConfigError>()
.is_some_and(|e| matches!(e, goose::config::base::ConfigError::DeserializeError(_)))
{
Err(StatusCode::UNPROCESSABLE_ENTITY)
} else {
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
}
}
}
@@ -196,6 +206,7 @@ pub async fn get_extensions(
responses(
(status = 200, description = "Extension added or updated successfully", body = String),
(status = 400, description = "Invalid request"),
(status = 422, description = "Could not serialize config.yaml"),
(status = 500, description = "Internal server error")
)
)]
+1 -2
View File
@@ -109,8 +109,7 @@ impl ExtensionManager {
/// Get all extensions and their configurations
pub fn get_all() -> Result<Vec<ExtensionEntry>> {
let config = Config::global();
let extensions: HashMap<String, ExtensionEntry> =
config.get_param("extensions").unwrap_or_default();
let extensions: HashMap<String, ExtensionEntry> = config.get_param("extensions")?;
Ok(Vec::from_iter(extensions.values().cloned()))
}
+1 -1
View File
@@ -1,4 +1,4 @@
mod base;
pub mod base;
mod experiments;
pub mod extensions;
+3
View File
@@ -84,6 +84,9 @@
"400": {
"description": "Invalid request"
},
"422": {
"description": "Could not serialize config.yaml"
},
"500": {
"description": "Internal server error"
}
+4
View File
@@ -178,6 +178,10 @@ export type AddExtensionErrors = {
* Invalid request
*/
400: unknown;
/**
* Could not serialize config.yaml
*/
422: unknown;
/**
* Internal server error
*/