mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Assertions with custom message
This commit is contained in:
parent
33013af37a
commit
23238d4d44
@ -80,8 +80,13 @@ pub fn repr(args: &mut Args) -> SourceResult<Value> {
|
|||||||
#[func]
|
#[func]
|
||||||
pub fn assert(args: &mut Args) -> SourceResult<Value> {
|
pub fn assert(args: &mut Args) -> SourceResult<Value> {
|
||||||
let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
|
let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
|
||||||
|
let message = args.named::<EcoString>("message")?;
|
||||||
if !v {
|
if !v {
|
||||||
bail!(span, "assertion failed");
|
if let Some(message) = message {
|
||||||
|
bail!(span, "assertion failed: {}", message);
|
||||||
|
} else {
|
||||||
|
bail!(span, "assertion failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user