From f2057cfae639b3863c317a27b1a6417429de94d6 Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 19 Nov 2026 11:22:26 -0600 Subject: [PATCH 1/2] feat(engine): classify data-loss notices --- crates/data/src/lib.rs | 1 + crates/data/src/loss.rs | 57 +++++++++++++++++ crates/engine/src/cmd/design.rs | 4 +- crates/engine/src/cmd/edit.rs | 66 ++++++++++++-------- crates/engine/src/cmd/service.rs | 12 ++-- crates/engine/src/lib.rs | 104 ++++++++++++++++++++----------- crates/engine/src/parameters.rs | 8 ++- crates/engine/src/tests.rs | 6 +- 8 files changed, 187 insertions(+), 71 deletions(-) create mode 100644 crates/data/src/loss.rs diff --git a/crates/data/src/lib.rs b/crates/data/src/lib.rs index 921c0895df..5556a70704 100644 --- a/crates/data/src/lib.rs +++ b/crates/data/src/lib.rs @@ -31,6 +31,7 @@ pub mod kml; pub mod landxml; pub mod lidar; pub mod login_address; +pub mod loss; pub mod mapinfo; pub mod mbtiles; pub mod memory; diff --git a/crates/data/src/loss.rs b/crates/data/src/loss.rs new file mode 100644 index 0000000000..393809de1f --- /dev/null +++ b/crates/data/src/loss.rs @@ -0,0 +1,57 @@ +//! Shared classification for data-loss notices, independent of their wording. + +/// What happened to the data. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum LossKind { + Dropped, + Changed, + Approximated, + Assumed, +} + +impl LossKind { + /// A language-independent name for this kind of loss. + pub const fn id(self) -> &'static str { + match self { + Self::Dropped => "dropped", + Self::Changed => "changed", + Self::Approximated => "approximated", + Self::Assumed => "assumed", + } + } +} + +/// The specific cause of a loss. Add causes here so producers use the same code for the same loss. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum LossCode { + DroppedLegend, + DroppedTime, + DroppedValue, + DroppedCalculationResult, + ChangedTruncated, +} + +/// A code's identifier, effect on the data, and what the user can do about it. +pub struct LossSpec { + pub id: &'static str, + pub kind: LossKind, + pub action: &'static str, +} + +impl LossCode { + /// The registry entry that supplies the untranslated identifier and remediation. + pub const fn spec(self) -> LossSpec { + use LossKind::{Changed, Dropped}; + let (id, kind, action) = match self { + Self::DroppedLegend => ("dropped.legend", Dropped, "Use a service with a shorter legend address."), + Self::DroppedTime => ("dropped.time", Dropped, "Write to a date-time field to keep the time of day."), + Self::DroppedValue => ("dropped.value", Dropped, "Correct the value or use a destination field that can hold it."), + Self::DroppedCalculationResult => { + ("dropped.calculation-result", Dropped, "Correct the expression or check the input rows named in the notice.") + } + Self::ChangedTruncated => ("changed.truncated", Changed, "Use a decimal field to keep the fractional part."), + }; + LossSpec { id, kind, action } + } +} diff --git a/crates/engine/src/cmd/design.rs b/crates/engine/src/cmd/design.rs index 89a4174362..42bf9db8bd 100644 --- a/crates/engine/src/cmd/design.rs +++ b/crates/engine/src/cmd/design.rs @@ -347,8 +347,8 @@ pub(crate) fn apply_with>(s: &mut Session, id: u32, changes: // Said once the edit is kept: a rejected one changed nothing. for (rule, field, losses, ty) in cuts { let by = crate::notice_text::NoticeText::format("Attribute rule {rule}", [("rule", rule.into())]); - for notice in losses.notices(by, &field, ty) { - s.notify_text(notice, false); + for (code, notice) in losses.notices(by, &field, ty) { + s.notify_loss(code, notice); } } Ok(()) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index fed4ce2a17..9885796f44 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -1,6 +1,7 @@ //! Edit tab: create and delete features, edit attributes and fields, of a layer or of a //! standalone table (`"table"`). +use rustgis_data::loss::LossCode; use rustgis_data::{Dataset, Field, FieldType, Geometry, GeometryType, Value}; use serde_json::{Value as Json, json}; use std::borrow::Cow; @@ -396,22 +397,30 @@ impl Cuts { /// The notices for what writing the whole-number or date field `field` cut, each starting with `by` /// (the command or rule that wrote it). Empty when nothing was cut. pub(crate) fn notices(&self, by: &str, field: &str) -> Vec { + self.classified(by, field).into_iter().map(|(_, text)| text).collect() + } + + /// Pairs each coercion message with its cause at the point the loss is counted. + fn classified(&self, by: &str, field: &str) -> Vec<(LossCode, String)> { let results = |n: usize| if n == 1 { "1 result".to_string() } else { format!("{n} results") }; let mut out = Vec::new(); if self.fractions > 0 { let their = if self.fractions == 1 { "its" } else { "their" }; - out.push(format!("{by}: '{field}' holds whole numbers, so {} lost {their} fraction", results(self.fractions))); + out.push(( + LossCode::ChangedTruncated, + format!("{by}: '{field}' holds whole numbers, so {} lost {their} fraction", results(self.fractions)), + )); } if self.past > 0 { - out.push(format!("{by}: '{field}' is null for {} past the 64-bit integer range", results(self.past))); + out.push((LossCode::DroppedValue, format!("{by}: '{field}' is null for {} past the 64-bit integer range", results(self.past)))); } if self.not_numbers > 0 { let are = if self.not_numbers == 1 { "isn't a number" } else { "aren't numbers" }; - out.push(format!("{by}: '{field}' is null for {} that {are}", results(self.not_numbers))); + out.push((LossCode::DroppedValue, format!("{by}: '{field}' is null for {} that {are}", results(self.not_numbers)))); } if self.times > 0 { let their = if self.times == 1 { "its" } else { "their" }; - out.push(format!("{by}: '{field}' holds dates, so {} kept only {their} day", results(self.times))); + out.push((LossCode::DroppedTime, format!("{by}: '{field}' holds dates, so {} kept only {their} day", results(self.times)))); } out } @@ -487,12 +496,15 @@ impl WriteLosses { /// The notices for what writing `field`, of type `ty`, lost, each starting with `by` (the /// command or rule that wrote it). Rows are numbered from 1, as `@row_number` numbers them. /// The error notices are templates a translated interface shows in its language. - pub(crate) fn notices(&self, by: NoticeText, field: &str, ty: FieldType) -> Vec { + pub(crate) fn notices(&self, by: NoticeText, field: &str, ty: FieldType) -> Vec<(LossCode, NoticeText)> { let rows = |n: usize| if n == 1 { "1 row".to_string() } else { format!("{n} rows") }; let english = by.english(); - let mut out: Vec = self.cuts.notices(&english, field).into_iter().map(NoticeText::from).collect(); + let mut out: Vec<_> = self.cuts.classified(&english, field).into_iter().map(|(code, text)| (code, text.into())).collect(); if self.unread > 0 { - out.push(format!("{english}: '{field}' is null in {}, whose result isn't a {} value", rows(self.unread), ty.label()).into()); + out.push(( + LossCode::DroppedValue, + format!("{english}: '{field}' is null in {}, whose result isn't a {} value", rows(self.unread), ty.label()).into(), + )); } for (fault, n, listed) in &self.errors { let numbers: Vec = listed.iter().map(|r| r.saturating_add(1).to_string()).collect(); @@ -501,15 +513,18 @@ impl WriteLosses { (_, false) => "{by}: '{field}' is null in {count} rows because of {cause} (rows {rows})", (_, true) => "{by}: '{field}' is null in {count} rows because of {cause} (rows {rows}…)", }; - out.push(NoticeText::format( - key, - [ - ("by", by.clone()), - ("field", field.to_string().into()), - ("count", n.to_string().into()), - ("cause", NoticeText::term(fault.describe())), - ("rows", numbers.join(", ").into()), - ], + out.push(( + LossCode::DroppedCalculationResult, + NoticeText::format( + key, + [ + ("by", by.clone()), + ("field", field.to_string().into()), + ("count", n.to_string().into()), + ("cause", NoticeText::term(fault.describe())), + ("rows", numbers.join(", ").into()), + ], + ), )); } out @@ -1416,10 +1431,7 @@ fn land_table_edit(s: &mut Session, p: &Json, command: &str) -> Option s.notify_text(text, notice.error), - None => s.notify(notice.text, notice.error), - } + s.relay_notice(notice); } Ok(answer) })()) @@ -1510,8 +1522,8 @@ fn evaluate(calc: &Calculation, ds: &Dataset, rows: Vec, ty: FieldType) - /// Says what Calculate Field's results lost in `field` ([`evaluate`]), even when a calculation /// rule writes the field afterwards: the rule may read the cut value, and says what it cuts itself. fn calculation_notices(s: &mut Session, field: &str, ty: FieldType, losses: &WriteLosses) { - for notice in losses.notices(NoticeText::term("Calculate Field"), field, ty) { - s.notify_text(notice, false); + for (code, notice) in losses.notices(NoticeText::term("Calculate Field"), field, ty) { + s.notify_loss(code, notice); } } @@ -1715,8 +1727,11 @@ mod tests { p["expression"] = json!(expression); let mark = s.notice_mark(); s.run("edit.calculateField", &p).unwrap(); - let notices: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); - assert_eq!(notices, said, "{expression}, table {table}"); + let notices = s.notices_since(mark); + assert_eq!(notices.iter().map(|n| n.text.as_str()).collect::>(), said, "{expression}, table {table}"); + assert!(notices.iter().all(|n| n.loss() == Some(LossCode::DroppedCalculationResult) + && n.severity == rustgis_data::diagnostics::Severity::Warning + && !n.error)); } } // The earlier calculator doesn't join a stored infinity as text either. @@ -1733,7 +1748,8 @@ mod tests { for row in [4, 4] { losses.write(row, (Value::Null, Some(rustgis_data::query::Fault::DivisionByZero)), FieldType::Double); } - let said: Vec = losses.notices(NoticeText::term("Rule"), "n", FieldType::Double).iter().map(NoticeText::english).collect(); + let said: Vec = + losses.notices(NoticeText::term("Rule"), "n", FieldType::Double).iter().map(|(_, text)| text.english()).collect(); assert_eq!(said, ["Rule: 'n' is null in 1 row because of a division by zero (row 5)"]); let calc = Calc::parse("'pop ' + Pop Est", &ds).unwrap(); assert_eq!(calc.eval_or_fault(&ds, 0), (Value::Null, Some(rustgis_data::query::Fault::NotANumber))); diff --git a/crates/engine/src/cmd/service.rs b/crates/engine/src/cmd/service.rs index fdaf47c720..4d2e40d236 100644 --- a/crates/engine/src/cmd/service.rs +++ b/crates/engine/src/cmd/service.rs @@ -968,10 +968,10 @@ pub(crate) fn adding_ahead(s: &mut Session, p: &Value) -> Result Option> { super::reads::take::(s, command).map(|(result, notices, losses)| { for loss in losses { - s.notify_loss(loss.template, loss.count); + s.notify_counted(loss.code, loss.template, loss.count); } for notice in notices { - s.notify(notice.text, notice.error); + s.relay_notice(notice); } result }) @@ -1096,7 +1096,7 @@ fn layer_source(layer: &mut Value, source: CapabilitySource) { /// Counts destinations, not pairs; clean discovery emits no credential-forwarding notice. fn notify_withheld(s: &mut Session, count: u32) { - s.notify_loss(rustgis_data::ogc::QUERY_WITHHELD_NOTICE, count); + s.notify_counted(None, rustgis_data::ogc::QUERY_WITHHELD_NOTICE, count); } /// Adds one of a service's layers: map layers as tiles (an overlay), a style as a style, features @@ -1300,7 +1300,11 @@ fn add_discovered(s: &mut Session, p: &Value, url: &str, want: &str, found: &Dis // and counted in a notice.) let legends = rustgis_map::tiles::checked_legends(layer.legends.iter().cloned()); let offered = layer.legends.len().min(rustgis_data::ogc::MAX_LEGENDS); - s.notify_loss(LEGENDS_LEFT_OUT_NOTICE, u32::try_from(offered.saturating_sub(legends.len())).unwrap_or(u32::MAX)); + s.notify_counted( + Some(rustgis_data::loss::LossCode::DroppedLegend), + LEGENDS_LEFT_OUT_NOTICE, + u32::try_from(offered.saturating_sub(legends.len())).unwrap_or(u32::MAX), + ); if !legends.is_empty() { add["legend"] = json!(legends); } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 9893de7459..a6f8b97a88 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -588,9 +588,15 @@ pub struct Notice { pub(crate) severity: rustgis_data::diagnostics::Severity, /// Describes a committed external write, which restoring a project cannot undo. written: bool, + loss: Option, } impl Notice { + /// The cause when this notice describes a classified data loss. + pub fn loss(&self) -> Option { + self.loss + } + /// Deferred interface text, or `None` for an ordinary notice whose text is already final. /// The formatter returns logical-order text; the front end shapes the complete result once. /// Arguments are redacted before retention, and the result has the ordinary notice limits. @@ -601,6 +607,7 @@ impl Notice { /// One counted, already-redacted loss, independent of the changes a command can roll back. struct LossNotice { + code: Option, template: &'static str, count: u32, text: rustgis_data::diagnostics::Redacted, @@ -3024,14 +3031,24 @@ impl Session { /// Publishes English diagnostics and retains redacted templates for translated interfaces. pub(crate) fn notify_text(&mut self, text: notice_text::NoticeText, error: bool) { + use rustgis_data::diagnostics::Severity; + self.publish_text(text, if error { Severity::Error } else { Severity::Info }, None); + } + + /// Reports loss from an in-memory result, with text for translated interfaces. + pub(crate) fn notify_loss(&mut self, code: rustgis_data::loss::LossCode, text: notice_text::NoticeText) { + self.publish_text(text, rustgis_data::diagnostics::Severity::Warning, Some(code)); + } + + /// Redacts deferred translations as well as the English notice before retaining them. + fn publish_text( + &mut self, + text: notice_text::NoticeText, + severity: rustgis_data::diagnostics::Severity, + loss: Option, + ) { let text = text.redacted(); - let mark = self.notices_given; - self.notify(text.english(), error); - if self.notices_given != mark - && let Some(notice) = self.notices.last_mut() - { - notice.localized = Some(text); - } + self.publish_notice(Self::redacted(&text.english()), severity, self.diagnostic_source, Some(text), false, loss); } /// Runs `f`, then says the true/false parameters it could not read: text taken as false, @@ -3079,59 +3096,73 @@ impl Session { self.notice_redacted(text, if error { Severity::Error } else { Severity::Info }); } - /// A counted loss that remains true after rollback, unlike a completion such as "Deleted - /// 3 features". Only static engine templates with `{n}` and a count enter this channel. - /// Counts saturate and repeated templates aggregate once per outer command. Text is redacted - /// before retention; at most 32 kinds are held, with excess counts reported as one overflow. - /// Outside a guard it is published immediately. A native panic caught by `guarded` follows - /// the same outermost drain as an error; nothing is saved in project or undo state. - pub(crate) fn notify_loss(&mut self, template: &'static str, count: u32) { - use rustgis_data::diagnostics::{Redacted, Severity}; + /// Counts a notice that remains true after rollback. Only static templates with `{n}` enter + /// this channel. Counts saturate and repeated templates with the same code aggregate once + /// per outer command. Unclassified advisories, such as withheld logins, have no code. + pub(crate) fn notify_counted(&mut self, code: Option, template: &'static str, count: u32) { if count == 0 { return; } + let text = |n: u32| Self::redacted(&template.replace("{n}", &n.to_string())); if self.depth == 0 { - self.notice_redacted(Redacted::new(&template.replace("{n}", &count.to_string())), Severity::Info); - } else if let Some(loss) = self.loss_notices.iter_mut().find(|loss| loss.template == template) { + self.publish_counted(text(count), code, self.diagnostic_source); + } else if let Some(loss) = self.loss_notices.iter_mut().find(|loss| loss.code == code && loss.template == template) { loss.count = loss.count.saturating_add(count); - loss.text = Redacted::new(&template.replace("{n}", &loss.count.to_string())); + loss.text = text(loss.count); } else if self.loss_notices.len() < MAX_LOSS_NOTICE_KINDS { - self.loss_notices.push(LossNotice { - template, - count, - text: Redacted::new(&template.replace("{n}", &count.to_string())), - source: self.diagnostic_source, - }); + self.loss_notices.push(LossNotice { code, template, count, text: text(count), source: self.diagnostic_source }); } else { self.loss_notice_overflow = self.loss_notice_overflow.saturating_add(count); } } - /// Publishes and empties runtime losses only after outermost success/error/panic cleanup. - /// Stored attribution keeps nested command losses assigned to their original command. + /// Publishes and empties runtime notices after outermost cleanup, retaining the originating command. fn flush_loss_notices(&mut self) { - use rustgis_data::diagnostics::Severity; for loss in std::mem::take(&mut self.loss_notices) { - self.notice_redacted_from(loss.text, Severity::Info, loss.source); + self.publish_counted(loss.text, loss.code, loss.source); } let overflow = std::mem::take(&mut self.loss_notice_overflow); if overflow > 0 { - self.notice(format!("{overflow} further loss(es) could not be described"), Severity::Info); + self.notify(format!("{overflow} further loss(es) could not be described"), false); } } - /// Uses current attribution for ordinary notices; delayed losses retain their own source. + fn publish_counted( + &mut self, + text: rustgis_data::diagnostics::Redacted, + code: Option, + source: Option<&'static str>, + ) { + use rustgis_data::diagnostics::Severity; + let severity = if code.is_some() { Severity::Warning } else { Severity::Info }; + self.publish_notice(text, severity, source, None, false, code); + } + fn notice_redacted(&mut self, text: rustgis_data::diagnostics::Redacted, severity: rustgis_data::diagnostics::Severity) { - self.notice_redacted_from(text, severity, self.diagnostic_source); + self.publish_notice(text, severity, self.diagnostic_source, None, false, None); + } + + /// Lands a worker's notice under the admitted command, preserving the notice's metadata. + pub(crate) fn relay_notice(&mut self, notice: Notice) { + self.publish_notice( + Self::redacted(¬ice.text), + notice.severity, + self.diagnostic_source, + notice.localized, + notice.written, + notice.loss, + ); } - /// The one publication path for the ordinary notice queue and diagnostics; called once per - /// loss at drain, so neither sink sees a duplicate from queuing and publication. - fn notice_redacted_from( + /// The one publication path for the notice queue and the diagnostic history. + fn publish_notice( &mut self, text: rustgis_data::diagnostics::Redacted, severity: rustgis_data::diagnostics::Severity, source: Option<&'static str>, + localized: Option, + written: bool, + loss: Option, ) { if severity == rustgis_data::diagnostics::Severity::Error && self.rerun_said.iter().any(|said| said == text.as_str()) { return; @@ -3140,9 +3171,10 @@ impl Session { self.notices.push(Notice { text: text.into_string(), error: severity == rustgis_data::diagnostics::Severity::Error, - localized: None, + localized, severity, - written: false, + written, + loss, }); self.notices_given += 1; if self.notices.len() > 200 { diff --git a/crates/engine/src/parameters.rs b/crates/engine/src/parameters.rs index 833e605ae1..cae3a3eca7 100644 --- a/crates/engine/src/parameters.rs +++ b/crates/engine/src/parameters.rs @@ -122,11 +122,11 @@ mod tests { const LOSS: &str = "{n} resource(s) were omitted at https://h.invalid/x?token=RGSYNTH_2"; let result = session.guarded("Loss rollback", true, |s| { s.guarded("Nested loss", true, |s| { - s.notify_loss(LOSS, 1); + s.notify_counted(Some(rustgis_data::loss::LossCode::DroppedLegend), LOSS, 1); Ok(Value::Null) })?; assert!(s.notices_since(mark).is_empty(), "the outer guard has not finished"); - s.notify_loss(LOSS, 2); + s.notify_counted(Some(rustgis_data::loss::LossCode::DroppedLegend), LOSS, 2); s.project.name = "temporary".into(); s.notify("Deleted 3 features", false); panic!("synthetic loss rollback"); @@ -135,7 +135,9 @@ mod tests { assert_eq!(session.project.name, name); let notices = session.notices_since(mark); assert_eq!(notices.iter().filter(|n| !n.error).count(), 1); - assert!(notices.iter().any(|n| !n.error && n.text.starts_with("3 resource(s)"))); + assert!(notices.iter().any(|n| n.loss() == Some(rustgis_data::loss::LossCode::DroppedLegend) + && n.severity == rustgis_data::diagnostics::Severity::Warning + && n.text.starts_with("3 resource(s)"))); assert!(notices.iter().all(|n| !n.text.contains("RGSYNTH_") && n.text != "Deleted 3 features")); let diagnostic_losses = session.diagnostics.records().into_iter().filter(|r| r.message.starts_with("3 resource(s)")).count(); assert_eq!(diagnostic_losses, 1); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index dba1aa016f..1cf8c738c6 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -329,7 +329,7 @@ fn scoped_table_writes_need_prepared_worker_results() { s.run("layer.addDataText", &json!({"fileName": "records.csv", "text": format!("n\n{}", "1\n".repeat(20_000))})).unwrap(); s.run("edit.enable", &json!({"on": true})).unwrap(); let scope = Scope::assistant(195509, Arc::new(Live)); - let p = json!({"table": "records", "field": "n", "expression": "n + 1"}); + let p = json!({"table": "records", "field": "n", "expression": "n + 1.5"}); let before = serde_json::to_value(&s.project.tables).unwrap(); let depth = s.undo_depth(); let error = s.run_scoped(scope.clone(), &Call::command("edit.calculateField", p.clone())).unwrap_err(); @@ -339,7 +339,11 @@ fn scoped_table_writes_need_prepared_worker_results() { let ahead = s.with_scope(scope, |s| read_ahead(s, "edit.calculateField", &p)).unwrap().unwrap(); assert!(ahead.reads()); let read = ahead.run(&rustgis_analysis::control::Control::stoppable()).unwrap(); + let mark = s.notice_mark(); read_land(&mut s, read).unwrap(); + let [notice] = s.notices_since(mark) else { panic!("expected one prepared loss notice") }; + assert_eq!(notice.loss(), Some(rustgis_data::loss::LossCode::ChangedTruncated)); + assert_eq!(notice.severity, rustgis_data::diagnostics::Severity::Warning); assert_eq!(s.project.tables[0].dataset.value(0, 0), &rustgis_data::Value::Int(2)); assert_eq!(s.undo_depth(), depth + 1); s.run("edit.undo", &Value::Null).unwrap(); From b4171eb432e88ff29de522f5f6b6f0443f6e99d5 Mon Sep 17 00:00:00 2001 From: mavrick Date: Thu, 19 Nov 2026 12:04:39 -0600 Subject: [PATCH 2/2] fix(engine): clarify counted loss warnings --- crates/data/src/loss.rs | 2 +- crates/engine/src/cmd/service.rs | 8 ++++---- crates/engine/src/lib.rs | 3 ++- crates/engine/src/parameters.rs | 27 +++++++++++++++++++++++++++ crates/engine/src/tests.rs | 4 +++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/data/src/loss.rs b/crates/data/src/loss.rs index 393809de1f..8b2d572122 100644 --- a/crates/data/src/loss.rs +++ b/crates/data/src/loss.rs @@ -44,7 +44,7 @@ impl LossCode { pub const fn spec(self) -> LossSpec { use LossKind::{Changed, Dropped}; let (id, kind, action) = match self { - Self::DroppedLegend => ("dropped.legend", Dropped, "Use a service with a shorter legend address."), + Self::DroppedLegend => ("dropped.legend", Dropped, "Use a service with short HTTP or HTTPS addresses for its legend pictures."), Self::DroppedTime => ("dropped.time", Dropped, "Write to a date-time field to keep the time of day."), Self::DroppedValue => ("dropped.value", Dropped, "Correct the value or use a destination field that can hold it."), Self::DroppedCalculationResult => { diff --git a/crates/engine/src/cmd/service.rs b/crates/engine/src/cmd/service.rs index 4d2e40d236..022648a150 100644 --- a/crates/engine/src/cmd/service.rs +++ b/crates/engine/src/cmd/service.rs @@ -141,8 +141,9 @@ const MAX_SERVICE_DOCUMENTS: usize = 32; /// well as its document count. The 32-document count is shared by all discovery kinds; /// this byte budget applies only to the linked dataset documents. pub(crate) const MAX_DATASET_BYTES: usize = if cfg!(test) { 64 << 10 } else { 64 << 20 }; -/// A notice for legend pictures a service listed that its layer cannot keep (an address too long). -const LEGENDS_LEFT_OUT_NOTICE: &str = "{n} legend picture(s) the service listed were left out: their addresses are too long"; +/// A notice for legend pictures the layer cannot keep because of their addresses. +const LEGENDS_LEFT_OUT_NOTICE: &str = + "{n} legend picture(s) the service listed were left out: their addresses are too long or do not use HTTP or HTTPS"; /// Most bytes of document addresses a listing repeats: each listed layer's `source_url` is its /// document's address, which nothing bounds (a landing page links to any collections address). @@ -1296,8 +1297,7 @@ fn add_discovered(s: &mut Session, p: &Value, url: &str, want: &str, found: &Dis } } } - // (Those the layer wouldn't keep, an address too long, are left out, not refused, - // and counted in a notice.) + // Count pictures left out because their addresses fail the layer's checks. let legends = rustgis_map::tiles::checked_legends(layer.legends.iter().cloned()); let offered = layer.legends.len().min(rustgis_data::ogc::MAX_LEGENDS); s.notify_counted( diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index a6f8b97a88..a4479c7e06 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -3123,7 +3123,8 @@ impl Session { } let overflow = std::mem::take(&mut self.loss_notice_overflow); if overflow > 0 { - self.notify(format!("{overflow} further loss(es) could not be described"), false); + // The overflow count may combine several causes and unclassified advisories. + self.warn(format!("{overflow} further counted notice occurrence(s) could not be described")); } } diff --git a/crates/engine/src/parameters.rs b/crates/engine/src/parameters.rs index cae3a3eca7..b95ac5a5a3 100644 --- a/crates/engine/src/parameters.rs +++ b/crates/engine/src/parameters.rs @@ -145,4 +145,31 @@ mod tests { session.guarded("Next command", false, |_| Ok(Value::Null)).unwrap(); assert!(session.notices_since(mark).is_empty()); } + + #[test] + fn counted_notice_overflow_warns_without_assigning_a_cause() { + use rustgis_data::{diagnostics::Severity, loss::LossCode}; + let mut session = crate::Session::new(crate::Project::default()); + session + .guarded("Count omissions", false, |s| { + // Seed the bounded channel to exercise overflow without adding more producers. + s.notify_counted(None, "{n} advisory", 1); + let first = &s.loss_notices[0]; + let (template, count, text) = (first.template, first.count, first.text.clone()); + s.loss_notices.resize_with(crate::MAX_LOSS_NOTICE_KINDS, || crate::LossNotice { + code: None, + template, + count, + text: text.clone(), + source: None, + }); + s.notify_counted(Some(LossCode::DroppedLegend), "{n} omitted legends", 2); + Ok(Value::Null) + }) + .unwrap(); + let overflow = session.notices.last().unwrap(); + assert_eq!(overflow.text, "2 further counted notice occurrence(s) could not be described"); + assert_eq!(overflow.severity, Severity::Warning); + assert_eq!(overflow.loss(), None); + } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1cf8c738c6..9e197583f7 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -21577,7 +21577,9 @@ fn service_legends_left_out_are_reported() { s.run("service.add", &json!({"url": "https://maps.example.com/wms", "layer": "roads", "text": WMS.replace("LEGEND", legend)})) .unwrap(); let notices = s.notices_since(mark); - let reported = notices.iter().any(|n| n.text.contains("1 legend picture(s) the service listed were left out")); + let reported = notices.iter().any(|n| { + n.loss() == Some(rustgis_data::loss::LossCode::DroppedLegend) && n.severity == rustgis_data::diagnostics::Severity::Warning + }); assert_eq!(reported, left_out, "{notices:?}"); assert_eq!(s.map().tiles.first().map(|t| t.legends.len()), Some(usize::from(!left_out))); }