Preserve config error causes when saving the approvals reviewer (#46036)

## Why

Failures to save `approvals_reviewer` in the TUI hide the underlying configuration error, leaving users without the details needed to fix it.

## What changed

Use `format_config_error` when displaying save failures so the message includes the error chain, including configuration file locations and parse errors.

## Testing

Add a regression test that introduces an unclosed array in `config.toml` after startup, attempts to save the approvals reviewer through the app server, and verifies the rendered error retains the parse failure and its location.

GitOrigin-RevId: bb29b5f8e61569e6c1c23a0c968e64091a95f72d
This commit is contained in:
Darius Karel authored and copyberry committed 2026-09-16 21:59:33 +00:00
1 parent a6d4741d39
commit 4fa7e82274
4 files changed
+50 -2

No files matched your search

+4 -2
View File
@@ -2335,8 +2335,10 @@ impl App {
error = %err,
"failed to persist approvals reviewer update"
);
self.chat_widget
.add_error_message(format!("Failed to save approvals reviewer: {err}"));
self.chat_widget.add_error_message(format!(
"Failed to save approvals reviewer: {}",
format_config_error(&err)
));
}
}
AppEvent::FetchExperimentalFeatures { thread_id, response_tx } => {
+2
View File
@@ -9,6 +9,8 @@ mod math_interruption_tests;
mod advanced_reasoning_tests;
#[path = "tests/agents_navigation_tests.rs"]
mod agents_navigation_tests;
#[path = "tests/approvals_reviewer_error_tests.rs"]
mod approvals_reviewer_error_tests;
#[path = "tests/backend_banner_fallback_tests.rs"]
mod backend_banner_fallback_tests;
#[path = "tests/backend_banner_recovery_tests.rs"]
@@ -0,0 +1,38 @@
//! Verify that approvals persistence failures retain the backend's actionable cause.
use super::*;
#[tokio::test]
async fn approvals_reviewer_error_retains_config_cause() -> Result<()> {
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
let config_path = codex_home.path().join("config.toml");
std::fs::write(&config_path, "")?;
let mut app_server = start_config_write_test_app_server(&app).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
while events.try_recv().is_ok() {}
// Simulate an external config edit after startup so the real batch-write
// reload fails, rather than injecting an already-formatted UI error.
std::fs::write(&config_path, "approvals_reviewer = [\n")?;
Box::pin(app.handle_event(
&mut tui,
&mut app_server,
AppEvent::UpdateApprovalsReviewer(ApprovalsReviewer::User),
))
.await?;
app_server.shutdown().await?;
let cell = match events.try_recv() {
Ok(AppEvent::InsertHistoryCell(cell)) => cell,
other => panic!("expected the persistence error, got {other:?}"),
};
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 120)).replace(
&config_path.to_string_lossy().to_string(),
"<CODEX_HOME>/config.toml",
);
assert!(rendered.contains("unclosed array"), "{rendered}");
insta::assert_snapshot!("approvals_reviewer_config_error", rendered);
Ok(())
}
@@ -0,0 +1,6 @@
---
source: tui/src/app/tests/approvals_reviewer_error_tests.rs
assertion_line: 34
expression: rendered
---
■ Failed to save approvals reviewer: config/batchWrite failed in TUI: config/batchWrite failed: failed to load configuration: <CODEX_HOME>/config.toml:1:24: unclosed array, expected `]` (code -32603)