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", "comemo",
"ecow", "ecow",
"if_chain", "if_chain",
"log",
"serde", "serde",
"typst", "typst",
"unscanny", "unscanny",

View File

@ -5,7 +5,7 @@ use std::hash::Hash;
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use comemo::{Prehashed, Track, Tracked, Validate}; use comemo::{Prehashed, Track, Tracked, Validate};
use ecow::{EcoString, EcoVec}; use ecow::{eco_format, EcoString, EcoVec};
use indexmap::IndexMap; use indexmap::IndexMap;
use super::{Content, Selector}; use super::{Content, Selector};
@ -388,11 +388,13 @@ impl Introspector {
let mut found = None; let mut found = None;
for elem in self.all().filter(|elem| elem.label() == Some(label)) { for elem in self.all().filter(|elem| elem.label() == Some(label)) {
if found.is_some() { 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 = 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. /// The total number pages.

View File

@ -1,12 +1,5 @@
// Test citations and bibliographies. // 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) #set page(width: 200pt)
= Details = Details
@ -41,3 +34,12 @@ And quark! @quark
= Multiple Bibs = Multiple Bibs
Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read") Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read")
#bibliography(("/files/works.bib", "/files/works_too.bib")) #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.] #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.] #link(<hey>)[Nope.]
--- ---
Text <hey> Text <hey>
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.] #link(<hey>)[Nope.]

View File

@ -10,14 +10,14 @@ See @setup.
As seen in @intro, we proceed. 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 @foo
--- ---
= First <foo> = First <foo>
= Second <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 @foo
--- ---