diff --git a/crates/engine/src/cmd/clipboard.rs b/crates/engine/src/cmd/clipboard.rs index d9e4c1b08b..ef95b78e95 100644 --- a/crates/engine/src/cmd/clipboard.rs +++ b/crates/engine/src/cmd/clipboard.rs @@ -194,5 +194,10 @@ fn copy_path(s: &mut Session, p: &Value) -> CmdResult { let path = path.ok_or_else(|| format!("{} isn't stored in a file", l.name))?; // A service layer's address is its source: copied without keys, tokens or its password, as // the details pane shows it and a saved project keeps a web address. - Ok(json!({"text": crate::sources::redact(&path)})) + let text = crate::sources::redact(&path); + if text != path { + // Not the layer's name: it may hold an address with a key of its own. + s.notify("The copied address leaves out part of the layer's address (keys, tokens, a password, a login or a fragment), so it may not work as it is", false); + } + Ok(json!({"text": text})) } diff --git a/crates/engine/src/cmd/design.rs b/crates/engine/src/cmd/design.rs index 7b11b318a4..0d1e37152f 100644 --- a/crates/engine/src/cmd/design.rs +++ b/crates/engine/src/cmd/design.rs @@ -939,8 +939,8 @@ fn polar_transform( }) } -/// [`modify`] for a move, turn or scale, which leaves a vertex missing a coordinate where it was: -/// says how many of the features it changed have one. +/// [`modify`] for a move, turn or scale, which leaves a vertex missing a coordinate (or with an +/// infinite one) where it was: says how many of the features it changed have one. fn move_features(s: &mut Session, mut change: impl FnMut((u32, usize), &Geometry) -> Result, String>) -> CmdResult { let mut missing = 0usize; let done = modify(s, |key, g| { @@ -953,7 +953,7 @@ fn move_features(s: &mut Session, mut change: impl FnMut((u32, usize), &Geometry Ok(moved) })?; if missing > 0 { - s.warn(format!("{missing} feature(s) have a vertex missing a coordinate, which was left where it was")); + s.warn(format!("{missing} feature(s) have a vertex missing a coordinate or with an infinite one, which was left where it was")); } Ok(done) } diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index f6bc99da35..939c624031 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -47,7 +47,7 @@ pub fn commands() -> Vec { C::new("layer.addEncodedPolyline", "Add Encoded Polyline", "Home › Add", add_encoded_polyline).roles(&[]).effects(crate::policy::Effects::NONE).params( r#"{"polyline": "encoded polyline text" | [texts] (one line each), "precision"?: 5 (Google) | 6 (OSRM, Valhalla), "name"?: text}"#, ), - C::new("layer.addDataText", "Add Data (from text)", "Home › Add", add_data_text).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"fileName": "name.geojson|.csv|.tsv", "text": string, "name"?: text, "x"?, "y"?, "wkt"?, "crs"?, "delimiter"? (as layer.addData, for delimited text), "layer"?, "paperSpace"? (as layer.addData, for a file of several layers)}"#), + C::new("layer.addDataText", "Add Data (from text)", "Home › Add", add_data_text).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"fileName": "name.geojson|.csv|.tsv|.city.json (CityJSON: all its layers)", "text": string, "name"?: text, "x"?, "y"?, "wkt"?, "crs"?, "delimiter"? (as layer.addData, for delimited text; crs also for a CityJSON model that doesn't say), "layer"?, "paperSpace"? (as layer.addData, for a file of several layers)}"#), C::new("layer.addSample", "Add Sample Data", "Home › Add › Add Data", add_sample).roles(&[]).effects(crate::policy::Effects::NONE).params(r#"{"name": "countries"|"cities"|"rivers"|"lakes"}"#), C::new("layer.remove", "Remove", "Layers", remove).roles(&[]).effects(crate::policy::Effects::NONE) .key("Delete") @@ -3226,10 +3226,10 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult { .and_then(Value::as_u64) .is_some_and(|id| u32::try_from(id).ok().and_then(|id| s.map().layer(id)).is_none()); if missing || added.gone(s.map()) { - return Err(format!("{url}: the layer its download added was taken away (undone) before the command ran again")); + return Err(format!("{url}: the layer its download added was removed or undone before the command ran again")); } if super::plugins::fetch::table_gone(&answer, &s.project) { - return Err(format!("{url}: the table its download added was taken away (undone) before the command ran again")); + return Err(format!("{url}: the table its download added was removed or undone before the command ran again")); } return added.answer_now(s.map(), &answer); } diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 2ed0c0afa3..f7fc9b8796 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -786,7 +786,7 @@ pub fn parse_arrangement(v: &Value) -> Result { let corner = o.get(*key).and_then(Value::as_str).map(str::trim).unwrap_or(""); homes[i] = CORNER_NAMES .iter() - .position(|c| *c == corner) + .position(|c| c.eq_ignore_ascii_case(corner)) .ok_or_else(|| format!("arrangement: \"{key}\" is \"top-left\", \"top-right\", \"bottom-left\" or \"bottom-right\""))?; } if (0..4).any(|i| homes[..i].contains(&homes[i])) { @@ -2062,7 +2062,7 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { _ => (format!("the {} and the {last}", rest.join(", the ")), "sit"), }; warnings - .push(format!("{names} {verb} on what the map shows, the freer corners having gone to the others: move by hand what matters")); + .push(format!("{names} {verb} on what the map shows, the freer places having gone to the others: move by hand what matters")); } for (i, (a, ra)) in placed.iter().enumerate() { for (b, rb) in placed.iter().skip(i + 1) { diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index e93caa077d..39541c1871 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -520,11 +520,16 @@ impl UrlWaits { } } - /// Downloads waited for past [`REQUEST_WAIT`] land as failed, and are remembered as given up: - /// their addresses, redacted, to be said (a notice with a key in it loses what follows it). - fn expire(&mut self) -> Vec { - let late: Vec<(u64, Value)> = - self.in_flight.iter().filter(|(.., at)| at.elapsed() >= REQUEST_WAIT).map(|(n, q, _)| (*n, q.clone())).collect(); + /// Downloads waited for past [`REQUEST_WAIT`] by `now` land as failed, and are remembered as + /// given up: their addresses, redacted, to be said (a notice with a key in it loses what + /// follows it). + fn expire_at(&mut self, now: Instant) -> Vec { + let late: Vec<(u64, Value)> = self + .in_flight + .iter() + .filter(|(.., at)| now.saturating_duration_since(*at) >= REQUEST_WAIT) + .map(|(n, q, _)| (*n, q.clone())) + .collect(); let mut addresses = Vec::new(); for (n, asked) in late { self.land(n, Err(format!("no download in {} minutes", REQUEST_WAIT.as_secs() / 60)), Added::default()); @@ -867,13 +872,19 @@ impl Session { /// what it answered this time. Its `layer.addUrl` calls answer what adding each download /// answered. Errors are also given as notices, as for any command. pub fn poll_plugin_retries(&mut self) -> Vec<(String, CmdResult)> { + self.poll_plugin_retries_at(Instant::now()) + } + + /// [`Session::poll_plugin_retries`] as at `now`: downloads waited for past [`REQUEST_WAIT`] + /// by then are given up (a test passes a later time instead of backdating the waits). + fn poll_plugin_retries_at(&mut self, now: Instant) -> Vec<(String, CmdResult)> { self.url_waits.documents_in(); if self.plugin_retries.is_empty() { return Vec::new(); } // Said here too: the command may go on without it, and what it answers goes nowhere. let minutes = REQUEST_WAIT.as_secs() / 60; - match self.url_waits.expire().as_slice() { + match self.url_waits.expire_at(now).as_slice() { [] => {} [url] => self.notify(format!("{url}: no download in {minutes} minutes, so its plugin command stopped waiting for it"), true), many => self.notify( @@ -1114,7 +1125,7 @@ mod tests { s.map_mut().layers[at] = other; s.rerun_landed = vec![(asked.clone(), answer, added)]; let e = s.run("layer.addUrl", &asked).unwrap_err(); - assert!(e.contains("taken away (undone)"), "{e}"); + assert!(e.contains("removed or undone"), "{e}"); // A tile layer (a GeoTIFF read in place answers its place in the list), then taken away. let tiles = json!({"url": "https://x.org/{z}/{x}/{y}.png", "name": "T"}); let answer = s.run("map.addTiles", &tiles); @@ -1135,7 +1146,7 @@ mod tests { s.run("map.removeTiles", &json!({"index": moved})).unwrap(); assert!(s.map().tiles.iter().any(|t| t.name == "T2")); let e = s.run("layer.addUrl", &asked).unwrap_err(); - assert!(e.contains("taken away (undone)"), "{e}"); + assert!(e.contains("removed or undone"), "{e}"); // A standalone table (a file with no geometry), then taken away. let answer = s.run("layer.addDataText", &json!({"fileName": "sites.csv", "text": "id,street\n1,Champ de Mars\n"})); assert!(answer.as_ref().unwrap()["table"].is_string(), "{answer:?}"); @@ -1143,7 +1154,7 @@ mod tests { assert_eq!(s.run("layer.addUrl", &asked), answer); s.run("table.remove", &json!({"table": "sites"})).unwrap(); let e = s.run("layer.addUrl", &asked).unwrap_err(); - assert!(e.contains("the table its download added was taken away (undone)"), "{e}"); + assert!(e.contains("the table its download added was removed or undone"), "{e}"); } /// A number lands only the read it was given for: a plugin's has no login, and a read that @@ -1173,7 +1184,6 @@ mod tests { /// Timeouts are one counted, redacted notice, and a real pinned command receives the failure. #[test] fn a_download_given_up_is_said_with_its_address() { - let Some(long_ago) = Instant::now().checked_sub(REQUEST_WAIT + Duration::from_secs(1)) else { return }; let mut s = Session::new(crate::project::Project::default()); let first = load_test_plugin("eng-slow-real"); let other = load_test_plugin("eng-slow-other"); @@ -1182,8 +1192,7 @@ mod tests { let mark = s.notice_mark(); s.poll_plugin_retries(); assert!(s.notices_since(mark).is_empty(), "it still has time"); - s.url_waits.in_flight[0].2 = long_ago; - let ran = s.poll_plugin_retries(); + let ran = s.poll_plugin_retries_at(Instant::now() + REQUEST_WAIT); assert!(ran[0].1.is_err(), "{ran:?}"); s.poll_plugin_retries(); let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.error && n.text.contains("stopped waiting")).collect(); @@ -1199,9 +1208,8 @@ mod tests { ask(&mut s, &first, json!({"url":"https://x.org/a.csv?token=hunter2"})).unwrap(); ask(&mut s, &other, json!({"url":"https://x.org/b.csv"})).unwrap(); let _taken = s.take_url_requests(); - s.url_waits.in_flight.iter_mut().for_each(|w| w.2 = long_ago); let mark = s.notice_mark(); - s.poll_plugin_retries(); + s.poll_plugin_retries_at(Instant::now() + REQUEST_WAIT); let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.error && n.text.contains("stopped waiting")).collect(); assert_eq!(said.len(), 1, "{said:?}"); assert!( diff --git a/crates/engine/src/cmd/plugins.rs b/crates/engine/src/cmd/plugins.rs index 48b4c8a846..da786e3190 100644 --- a/crates/engine/src/cmd/plugins.rs +++ b/crates/engine/src/cmd/plugins.rs @@ -680,6 +680,6 @@ mod tests { // A layer undone while the command waited: said, not named. s.rerun_landed = vec![(asked.clone(), Ok(json!({"layer": 4_000_000})), Default::default())]; let e = s.run("layer.addUrl", &asked).unwrap_err(); - assert!(e.contains("taken away (undone)"), "{e}"); + assert!(e.contains("removed or undone"), "{e}"); } } diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index 9f347ef027..d2fcd3db9d 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -39,6 +39,7 @@ pub fn commands() -> Vec { let ext = Path::new(path).extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); let gpkg = gpkg_table(p, &ext)?; let t = s.project.tables.get(s.table_index(p)?).ok_or("no such table")?; + let default = t.dataset.name.clone(); // Tables may retain geometry and its import losses, just as feature layers do. let notes = rustgis_data::export_notes([(&t.dataset, t.dataset.extent())], path, Crs::LonLat); let mut dbf_notes = Vec::new(); @@ -56,7 +57,7 @@ pub fn commands() -> Vec { s.notify(note, false); } let mut out = json!({"path": path}); - report_table(s, path, &gpkg, table, &mut out); + report_table(s, path, &gpkg, &default, table, &mut out); Ok(out) }).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)) .params( @@ -91,8 +92,26 @@ pub fn gpkg_table(p: &Value, ext: &str) -> Result { /// an export into an existing GeoPackage also says so, what went with a replaced table, and /// which views and triggers elsewhere name it. Layers read in place from a replaced table read /// it again. -fn report_table(s: &mut Session, path: &str, gpkg: &GpkgTable, table: Option, out: &mut Value) { +fn report_table(s: &mut Session, path: &str, gpkg: &GpkgTable, default: &str, table: Option, out: &mut Value) { let Some(table) = table else { return }; + // A new file's table is said only when it isn't the name asked for, or by default the + // layer's (a reserved name is prefixed, control characters and edge spaces dropped); one + // added to or replaced in a file is always named below. + let asked = gpkg.name.as_deref().unwrap_or(default); + if gpkg.mode == GpkgMode::NewFile && asked != table.table { + let note = if asked.trim().is_empty() { + format!("{path}: wrote the table {}, as there was no name to give it", table.table) + } else { + // Escaped: a control character in the name would otherwise reach the terminal. + let asked: String = + asked.chars().map(|c| if c.is_control() { c.escape_default().to_string() } else { c.to_string() }).collect(); + format!( + "{path}: wrote the table {} instead of '{asked}' (GeoPackage table names can't start with gpkg_, sqlite_ or rtree_, and lose control characters and edge spaces)", + table.table + ) + }; + s.notify(note, false); + } if gpkg.mode != GpkgMode::NewFile { let (reread, failed) = if table.replaced { super::gpkg::reset_sources(s, Path::new(path), &table.table, true) } else { (0, Vec::new()) }; @@ -295,9 +314,10 @@ fn write_layer(l: &rustgis_map::Layer, path: &str, asked: Option, gpkg: Gpk // (layers reading a replaced table) is at hand. let written_path = Some(path.to_string()); let path = path.to_string(); + let default = ds.name.clone(); let then: Option = table.map(|t| { Box::new(move |s: &mut Session, out: &mut Value| { - report_table(s, &path, &gpkg, Some(t), out); + report_table(s, &path, &gpkg, &default, Some(t), out); Ok(()) }) as super::exports::Then }); diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index 4af97f16fb..75aa418d58 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -270,7 +270,9 @@ fn terrain(s: &mut Session, p: &Value) -> CmdResult { if let TerrainSource::Layer(n) = &t.source && m.layers.iter().filter(|l| l.name.eq_ignore_ascii_case(n)).count() > 1 { - let e = format!("two layers are called '{n}': rename one, then turn Terrain on"); + let e = format!( + "more than one layer is called '{n}': give the DEM a name of its own, then try again naming it (Terrain stays as it was)" + ); // A terrain that was on stays as it was. if let Some(old) = old_terrain { m.view.terrain = Some(old); diff --git a/crates/engine/src/service_logins.rs b/crates/engine/src/service_logins.rs index 6a86ede41f..1a746e157c 100644 --- a/crates/engine/src/service_logins.rs +++ b/crates/engine/src/service_logins.rs @@ -319,8 +319,10 @@ pub fn request(s: &mut Session, connection: Option<&str>, url: &str) -> Result>(); (ran.is_ok(), said) }; - let one = ["1 feature(s) have a vertex missing a coordinate, which was left where it was"]; + let one = ["1 feature(s) have a vertex missing a coordinate or with an infinite one, which was left where it was"]; let edits = [("edit.move", json!({"dx": 1000.0})), ("edit.rotate", json!({"angle": 10.0})), ("edit.scale", json!({"factor": 1.5}))]; let near_equator = boxed(10.0, 10.0, 11.0, 11.0); for ring in [polar_ring(), near_equator] { @@ -656,7 +656,10 @@ fn a_vertex_missing_a_coordinate_left_where_it_was_is_counted() { let features = vec![polygon(two), polygon(once), polygon(boxed(30.0, 10.0, 31.0, 11.0)), Geometry::Point(Coord::new(f64::NAN, 10.0))]; let (mut s, _) = layer(GeometryType::Polygon, features); let (ran, text) = said(&mut s, "edit.rotate", &json!({"angle": 10.0})); - assert!(ran && text == ["2 feature(s) have a vertex missing a coordinate, which was left where it was"], "{text:?}"); + assert!( + ran && text == ["2 feature(s) have a vertex missing a coordinate or with an infinite one, which was left where it was"], + "{text:?}" + ); // A refused edit (a polygon reaching a pole can't be turned yet) says nothing of the kind. let mut cap = polar_ring(); cap[0].y = -90.0; diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 6f30d91a25..eec05e108e 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -2877,8 +2877,9 @@ pub fn start_geolibre_load(app: &mut RustGisApp) { app.gp.web_load = Some(slot); } +/// What a slot holds, taken out; a poisoned slot is still read, as its writer fills it anyway. fn take(slot: &crate::Slot) -> Option { - slot.lock().ok().and_then(|mut s| s.take()) + slot.lock().unwrap_or_else(std::sync::PoisonError::into_inner).take() } /// Picks up what the browser's GeoLibre runner finished: the tool list, or a tool run. @@ -6928,6 +6929,24 @@ pub(crate) fn layout_menu(app: &mut RustGisApp, ui: &mut Ui, n: &str) { mod tests { use super::*; + /// A slot poisoned by a panicking writer that filled it anyway is still read, or the pane + /// waiting on it would wait forever. + #[cfg(not(target_arch = "wasm32"))] + #[test] + fn a_poisoned_slot_is_still_taken() { + let slot: crate::Slot = crate::Slot::default(); + let writer = slot.clone(); + let _ = std::thread::spawn(move || { + let mut held = writer.lock().unwrap(); + *held = Some(7); + panic!("the writer fails after filling the slot"); + }) + .join(); + assert!(slot.is_poisoned()); + assert_eq!(take(&slot), Some(7)); + assert_eq!(take(&slot), None, "taken once"); + } + /// Run starts a built-in tool on a thread of its own: the pane shows it running, with Cancel, /// and its result lands as gp.run's would, with its layer and history. #[cfg(not(target_arch = "wasm32"))]