Keep missing column errors separate from detected columns

This commit is contained in:
Dandaedre 2026-11-05 07:23:46 +01:00
parent 53f0d1fd88
commit 39d5bb1fe7
3 changed files with 76 additions and 19 deletions

View File

@ -547,11 +547,10 @@ fn infer_inner(
selected.contains_key(required)
};
if !present {
diagnostics.push(err(
diagnostics.push(Diagnostic::new(
1,
"MISSING_COLUMN",
table,
header,
0,
&table.name,
format!("Cannot infer {required}; clarify headers or map the column"),
));
}

View File

@ -1497,10 +1497,15 @@ impl App {
.collect::<std::collections::BTreeSet<_>>()
.len();
let column_word = if affected == 1 { "column" } else { "columns" };
let affected_summary = if affected == 0 {
String::new()
} else {
format!("{affected} {column_word} · ")
};
ui.colored_label(
PREVIEW_AMBER,
format!(
"! Column mapping needs attention · {affected} {column_word} · {} issues",
"! Column mapping needs attention · {affected_summary}{} issues",
errors.len()
),
);
@ -1551,12 +1556,32 @@ impl App {
|| (column_choice(&profile, c).is_none()
&& suggestions.get(&c) == Some(&"Duration"))
});
let missing = occurrences
.iter()
.all(|error| error.code == "MISSING_COLUMN");
let advice: std::collections::BTreeSet<_> = occurrences
.iter()
.map(|error| column_issue_advice(&error.code, duration))
.map(|error| {
if error.code == "MISSING_COLUMN" {
if error.message.starts_with("Cannot infer title;") {
return ("Title column missing", "Choose Title for the appropriate column below.");
}
if error.message.starts_with("Cannot infer start;") {
return ("Start column missing", "Choose Start or Start–end for the appropriate column below.");
}
}
column_issue_advice(&error.code, duration)
})
.collect();
let title = column.map_or_else(
|| "Sheet / settings".into(),
|| {
if missing {
"Missing column"
} else {
"Sheet / settings"
}
.into()
},
|c| format!("Column {}", column_name(c)),
);
ui.horizontal_wrapped(|ui| {
@ -1587,7 +1612,7 @@ impl App {
mapping_focus = Some(("warning".into(), vec![column]));
mapping_focus_until = Some(now + COLUMN_FOCUS_PULSE_SECONDS);
}
} else if ui.button("Open Setup…").clicked() {
} else if !missing && ui.button("Open Setup…").clicked() {
self.tab = Tab::Setup;
self.settings = true;
}
@ -1595,17 +1620,19 @@ impl App {
for (reason, action) in advice {
ui.label(format!("{reason}. {action}"));
}
egui::CollapsingHeader::new(RichText::new("Affected cells").weak())
.id_salt(("column_locations", &table.name, column))
.show(ui, |ui| {
ui.weak(
occurrences
.iter()
.map(|error| error.location.as_str())
.collect::<Vec<_>>()
.join(", "),
);
});
if column.is_some() {
egui::CollapsingHeader::new(RichText::new("Affected cells").weak())
.id_salt(("column_locations", &table.name, column))
.show(ui, |ui| {
ui.weak(
occurrences
.iter()
.map(|error| error.location.as_str())
.collect::<Vec<_>>()
.join(", "),
);
});
}
}
}
}
@ -2919,6 +2946,35 @@ mod tests {
);
}
#[test]
fn missing_title_does_not_blame_a_detected_timing_column() {
let mut app = sample();
app.review_view = ReviewView::Columns;
app.tables[0].rows[0][2].text = "Unrecognised".into();
let errors = crate::detect::infer(&app.tables[0], &Profile::default()).unwrap_err();
let missing = errors
.iter()
.find(|error| error.code == "MISSING_COLUMN")
.unwrap();
assert_eq!(missing.location, "Show");
assert_eq!(diagnostic_column(missing, &app.tables[0]), None);
let ctx = egui::Context::default();
configure_style(&ctx);
render(&mut app, &ctx, [1200.0, 1400.0], vec![]);
let labels = render(&mut app, &ctx, [1200.0, 1400.0], vec![]);
assert!(
labels
.iter()
.any(|(text, _)| text.starts_with("Title column missing."))
);
assert!(labels.iter().any(|(text, _)| text == "Suggested: Start"));
assert!(!labels.iter().any(|(text, _)| matches!(
text.as_str(),
"Needs attention" | "Review column…" | "Affected cells"
)));
assert!(app.mapping_focus.is_none());
}
#[test]
fn repeated_formula_errors_are_one_actionable_column_issue() {
let cells = |values: &[&str]| {

View File

@ -123,6 +123,8 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
scrolls to and highlights the affected column; columns needing attention remain
amber. Expand **Complete error log** to read or copy every original diagnostic
and source location. This grouping changes only the GUI summary, not CLI logs.
Missing required columns are reported at sheet level: no unrelated column is
highlighted, and existing role suggestions remain available.
When detection is blocked,
recognised headers still provide hints; these do not replace validation. Expand **Detection evidence** for
full inference and validation details; hover the **Columns** tab for a compact