Say which label occurs never or multiple times in error message

This commit is contained in:
Laurenz 2023-10-30 22:59:24 +01:00
parent 90cd1a5a09
commit 55296a9196
5 changed files with 19 additions and 14 deletions

1
Cargo.lock generated
View file

@ -2888,6 +2888,7 @@ dependencies = [
"comemo",
"ecow",
"if_chain",
"log",
"serde",
"typst",
"unscanny",

View file

@ -5,7 +5,7 @@ use std::hash::Hash;
use std::num::NonZeroUsize;
use comemo::{Prehashed, Track, Tracked, Validate};
use ecow::{EcoString, EcoVec};
use ecow::{eco_format, EcoString, EcoVec};
use indexmap::IndexMap;
use super::{Content, Selector};
@ -388,11 +388,13 @@ impl Introspector {
let mut found = None;
for elem in self.all().filter(|elem| elem.label() == Some(label)) {
if found.is_some() {
bail!("label occurs multiple times in the document");
bail!("label `{}` occurs multiple times in the document", label.repr());
}
found = Some(elem.clone());
}
found.ok_or_else(|| "label does not exist in the document".into())
found.ok_or_else(|| {
eco_format!("label `{}` does not exist in the document", label.repr())
})
}
/// The total number pages.

View file

@ -1,12 +1,5 @@
// Test citations and bibliographies.
---
// Test ambiguous reference.
= Introduction <arrgh>
// Error: 1-7 label occurs in the document and its bibliography
@arrgh
#bibliography("/files/works.bib")
---
#set page(width: 200pt)
= Details
@ -41,3 +34,12 @@ And quark! @quark
= Multiple Bibs
Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read")
#bibliography(("/files/works.bib", "/files/works_too.bib"))
---
// Test ambiguous reference.
= Introduction <arrgh>
// Error: 1-7 label occurs in the document and its bibliography
@arrgh
#bibliography("/files/works.bib")

View file

@ -67,11 +67,11 @@ Text <hey>
#link(<hey>)[Go to text.]
---
// Error: 2-20 label does not exist in the document
// Error: 2-20 label `<hey>` does not exist in the document
#link(<hey>)[Nope.]
---
Text <hey>
Text <hey>
// Error: 2-20 label occurs multiple times in the document
// Error: 2-20 label `<hey>` occurs multiple times in the document
#link(<hey>)[Nope.]

View file

@ -10,14 +10,14 @@ See @setup.
As seen in @intro, we proceed.
---
// Error: 1-5 label does not exist in the document
// Error: 1-5 label `<foo>` does not exist in the document
@foo
---
= First <foo>
= Second <foo>
// Error: 1-5 label occurs multiple times in the document
// Error: 1-5 label `<foo>` occurs multiple times in the document
@foo
---