mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Change error when accessing non-existant label (#5571)
This commit is contained in:
parent
257764181e
commit
21e608e6e9
@ -211,9 +211,10 @@ impl Content {
|
|||||||
/// instead.
|
/// instead.
|
||||||
pub fn get_by_name(&self, name: &str) -> Result<Value, FieldAccessError> {
|
pub fn get_by_name(&self, name: &str) -> Result<Value, FieldAccessError> {
|
||||||
if name == "label" {
|
if name == "label" {
|
||||||
if let Some(label) = self.label() {
|
return self
|
||||||
return Ok(label.into_value());
|
.label()
|
||||||
}
|
.map(|label| label.into_value())
|
||||||
|
.ok_or(FieldAccessError::Unknown);
|
||||||
}
|
}
|
||||||
let id = self.elem().field_id(name).ok_or(FieldAccessError::Unknown)?;
|
let id = self.elem().field_id(name).ok_or(FieldAccessError::Unknown)?;
|
||||||
self.get(id, None)
|
self.get(id, None)
|
||||||
|
@ -88,3 +88,7 @@ _Visible_
|
|||||||
#set heading(numbering: "1.")
|
#set heading(numbering: "1.")
|
||||||
// Warning: 1-4 label `<a>` is not attached to anything
|
// Warning: 1-4 label `<a>` is not attached to anything
|
||||||
<a>
|
<a>
|
||||||
|
|
||||||
|
--- label-non-existent-error ---
|
||||||
|
// Error: 5-10 sequence does not have field "label"
|
||||||
|
#[].label
|
||||||
|
Loading…
x
Reference in New Issue
Block a user