Skip to content

Commit 133485c

Browse files
committed
fix(errors): keep recursive inclusion errors concise
1 parent f562bd6 commit 133485c

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/webserver/database/error_highlighting.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ impl std::error::Error for NicePositionedError {
9595
}
9696
}
9797

98+
pub(super) fn is_positioned_error(error: &anyhow::Error) -> bool {
99+
error.downcast_ref::<NicePositionedError>().is_some()
100+
}
101+
98102
/// Display a database error without any position information
99103
#[must_use]
100104
pub(super) fn display_db_error(

‎src/webserver/database/execute_queries.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::pin::Pin;
88
use tracing::Instrument;
99

1010
use super::csv_import::run_csv_import;
11-
use super::error_highlighting::{display_stmt_db_error, display_stmt_error};
11+
use super::error_highlighting::{display_stmt_db_error, display_stmt_error, is_positioned_error};
1212
use super::sql::{
1313
DatabaseQuery, FileStatement, OutputColumn, Query, QueryBody, SingleRowQuery, SourceSpan,
1414
SqlFile,
@@ -301,7 +301,7 @@ fn with_stmt_position(
301301
query_position: SourceSpan,
302302
error: anyhow::Error,
303303
) -> anyhow::Error {
304-
if error.downcast_ref::<ErrorWithStatus>().is_some() {
304+
if error.downcast_ref::<ErrorWithStatus>().is_some() || is_positioned_error(&error) {
305305
error
306306
} else {
307307
display_stmt_error(source_file, query_position, error)

‎src/webserver/database/sqlpage_functions/functions/run_sql.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(super) async fn run_sql<'a>(
7575
}
7676
FinishedQuery => log::trace!("run_sql: Finished query"),
7777
Error(err) => {
78-
return Err(err.context(format!("run_sql: unable to run {sql_file_path:?}")));
78+
return Err(err);
7979
}
8080
}
8181
}

‎tests/sql_test_files/mod.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ fn assert_html_test(body: &str, test_file: &std::path::Path, stem: &str) {
257257
expected,
258258
test_file.display()
259259
);
260+
if stem == "error_too_many_nested_inclusions" {
261+
assert!(
262+
!body.contains("run_sql: unable to run"),
263+
"Recursive inclusion error should not repeat run_sql context: {}",
264+
test_file.display()
265+
);
266+
}
260267
} else {
261268
if let Some(error) = extract_error(body) {
262269
panic!("Error in {}: {}", test_file.display(), error);

0 commit comments

Comments
 (0)