mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Gracefully handle error if field was not defined (#2110)
This commit is contained in:
parent
3ca4c94870
commit
14d28dbf4e
@ -83,7 +83,7 @@ fn retrieve(
|
|||||||
/// Format the query result in the output format.
|
/// Format the query result in the output format.
|
||||||
fn format(elements: Vec<Content>, command: &QueryCommand) -> StrResult<String> {
|
fn format(elements: Vec<Content>, command: &QueryCommand) -> StrResult<String> {
|
||||||
if command.one && elements.len() != 1 {
|
if command.one && elements.len() != 1 {
|
||||||
bail!("expected exactly one element, found {}", elements.len())
|
bail!("expected exactly one element, found {}", elements.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mapped: Vec<_> = elements
|
let mapped: Vec<_> = elements
|
||||||
@ -95,7 +95,10 @@ fn format(elements: Vec<Content>, command: &QueryCommand) -> StrResult<String> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if command.one {
|
if command.one {
|
||||||
serialize(&mapped[0], command.format)
|
let Some(value) = mapped.get(0) else {
|
||||||
|
bail!("no such field found for element");
|
||||||
|
};
|
||||||
|
serialize(value, command.format)
|
||||||
} else {
|
} else {
|
||||||
serialize(&mapped, command.format)
|
serialize(&mapped, command.format)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user