mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +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]
|
||||
pub fn assert(args: &mut Args) -> SourceResult<Value> {
|
||||
let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
|
||||
let message = args.named::<EcoString>("message")?;
|
||||
if !v {
|
||||
bail!(span, "assertion failed");
|
||||
if let Some(message) = message {
|
||||
bail!(span, "assertion failed: {}", message);
|
||||
} else {
|
||||
bail!(span, "assertion failed");
|
||||
}
|
||||
}
|
||||
Ok(Value::None)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user