Handle missing keys with a default (#3753)

Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
Douwe Osinga
2025-08-01 21:13:30 +02:00
committed by GitHub
parent ba9981d1fc
commit 1a8b3b1a42
3 changed files with 19 additions and 12 deletions
@@ -7,9 +7,9 @@ use axum::{
Json, Router,
};
use etcetera::{choose_app_strategy, AppStrategy};
use goose::config::Config;
use goose::config::APP_STRATEGY;
use goose::config::{extensions::name_to_key, PermissionManager};
use goose::config::{Config, ConfigError};
use goose::config::{ExtensionConfigManager, ExtensionEntry};
use goose::model::ModelConfig;
use goose::providers::base::ProviderMetadata;
@@ -142,7 +142,7 @@ pub async fn remove_config(
request_body = ConfigKeyQuery,
responses(
(status = 200, description = "Configuration value retrieved successfully", body = Value),
(status = 404, description = "Configuration key not found")
(status = 500, description = "Unable to get the configuration value"),
)
)]
pub async fn read_config(
@@ -160,17 +160,24 @@ pub async fn read_config(
}
let config = Config::global();
match config.get(&query.key, query.is_secret) {
let response_value = match config.get(&query.key, query.is_secret) {
Ok(value) => {
if query.is_secret {
Ok(Json(Value::Bool(true)))
Value::Bool(true)
} else {
Ok(Json(value))
value
}
}
Err(_) => Err(StatusCode::NOT_FOUND),
}
Err(ConfigError::NotFound(_)) => {
if query.is_secret {
Value::Bool(false)
} else {
Value::Null
}
}
Err(_) => return Err(StatusCode::INTERNAL_SERVER_ERROR),
};
Ok(Json(response_value))
}
#[utoipa::path(
+2 -2
View File
@@ -333,8 +333,8 @@
}
}
},
"404": {
"description": "Configuration key not found"
"500": {
"description": "Unable to get the configuration value"
}
}
}
+2 -2
View File
@@ -1015,9 +1015,9 @@ export type ReadConfigData = {
export type ReadConfigErrors = {
/**
* Configuration key not found
* Unable to get the configuration value
*/
404: unknown;
500: unknown;
};
export type ReadConfigResponses = {