mirror of
https://github.com/openai/codex.git
synced 2026-05-18 18:22:39 +00:00
## Why App-server had repeated hand-built JSON-RPC error objects for standard error shapes. Using the shared helpers keeps the common `invalid_request`, `invalid_params`, and `internal_error` construction in one place and reduces the chance of new call sites drifting from the common error payload shape. ## What changed - Replaced manual standard JSON-RPC error object creation with `internal_error(...)`, `invalid_request(...)`, and `invalid_params(...)` across app-server request processors and runtime paths. - Removed local duplicate helper definitions from search and review request handling. - Preserved existing structured `data` payloads by creating the shared helper error first and then attaching the existing metadata. - Left custom non-standard errors and raw error-code assertions intact. ## Validation - `cargo test -p codex-app-server`
36 lines
1.2 KiB
Rust
36 lines
1.2 KiB
Rust
use super::*;
|
|
|
|
fn cloud_requirements_load_error(err: &std::io::Error) -> Option<&CloudRequirementsLoadError> {
|
|
let mut current: Option<&(dyn std::error::Error + 'static)> = err
|
|
.get_ref()
|
|
.map(|source| source as &(dyn std::error::Error + 'static));
|
|
while let Some(source) = current {
|
|
if let Some(cloud_error) = source.downcast_ref::<CloudRequirementsLoadError>() {
|
|
return Some(cloud_error);
|
|
}
|
|
current = source.source();
|
|
}
|
|
None
|
|
}
|
|
|
|
pub(super) fn config_load_error(err: &std::io::Error) -> JSONRPCErrorError {
|
|
let data = cloud_requirements_load_error(err).map(|cloud_error| {
|
|
let mut data = serde_json::json!({
|
|
"reason": "cloudRequirements",
|
|
"errorCode": format!("{:?}", cloud_error.code()),
|
|
"detail": cloud_error.to_string(),
|
|
});
|
|
if let Some(status_code) = cloud_error.status_code() {
|
|
data["statusCode"] = serde_json::json!(status_code);
|
|
}
|
|
if cloud_error.code() == CloudRequirementsLoadErrorCode::Auth {
|
|
data["action"] = serde_json::json!("relogin");
|
|
}
|
|
data
|
|
});
|
|
|
|
let mut error = invalid_request(format!("failed to load configuration: {err}"));
|
|
error.data = data;
|
|
error
|
|
}
|