mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-10 01:50:22 -06:00
Variables: Rename reports a missing variable or data set before a taken name
variable.rename and dataset.rename checked whether newName was taken before checking that name exists, so renaming a missing name onto a taken one said the new name already exists. Both now report the missing name first.
This commit is contained in:
@@ -160,6 +160,9 @@ fn rename(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let from = var_name(p, C)?;
|
||||
let to = named(p.get("newName").and_then(Value::as_str), "newName", C)?;
|
||||
let st = s.doc()?;
|
||||
if st.doc.variables.variable(&from).is_none() {
|
||||
return Err(bad(C, format!("no variable named `{from}`")));
|
||||
}
|
||||
if st.doc.variables.variable(&to).is_some() {
|
||||
return Err(bad(C, format!("variable `{to}` already exists")));
|
||||
}
|
||||
@@ -357,6 +360,9 @@ fn dataset_rename(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let from = var_name(p, C)?;
|
||||
let to = named(p.get("newName").and_then(Value::as_str), "newName", C)?;
|
||||
let st = s.doc()?;
|
||||
if st.doc.variables.dataset(&from).is_none() {
|
||||
return Err(bad(C, format!("no dataset named `{from}`")));
|
||||
}
|
||||
if st.doc.variables.dataset(&to).is_some() {
|
||||
return Err(bad(C, format!("dataset `{to}` already exists")));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user