diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/elements.rs | 20 | ||||
| -rw-r--r-- | src/library/layout.rs | 2 | ||||
| -rw-r--r-- | src/library/text.rs | 2 | ||||
| -rw-r--r-- | src/library/utility.rs | 8 |
4 files changed, 19 insertions, 13 deletions
diff --git a/src/library/elements.rs b/src/library/elements.rs index 3d318d36..e021c0c6 100644 --- a/src/library/elements.rs +++ b/src/library/elements.rs @@ -1,8 +1,10 @@ use std::f64::consts::SQRT_2; +use std::io; use decorum::N64; use super::*; +use crate::diag::Error; use crate::layout::{ BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode, Paint, }; @@ -13,13 +15,17 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { let width = args.named("width")?; let height = args.named("height")?; - let file = ctx.resolve(&path.v, path.span)?; - let node = match ctx.images.load(file) { - Some(id) => ImageNode { id, width, height }, - None => bail!(args.file, path.span, "failed to load image"), - }; - - Ok(Value::template(move |ctx| ctx.push_into_par(node))) + let full = ctx.relpath(path.v.as_str()); + let id = ctx.images.load(&full).map_err(|err| { + Error::boxed(args.source, path.span, match err.kind() { + io::ErrorKind::NotFound => "file not found".into(), + _ => format!("failed to load image ({})", err), + }) + })?; + + Ok(Value::template(move |ctx| { + ctx.push_into_par(ImageNode { id, width, height }) + })) } /// `rect`: A rectangle with optional content. diff --git a/src/library/layout.rs b/src/library/layout.rs index 727bbcc3..0d778206 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -6,7 +6,7 @@ use crate::paper::{Paper, PaperClass}; pub fn page(_: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { let paper = match args.eat::<Spanned<EcoString>>() { Some(name) => match Paper::from_name(&name.v) { - None => bail!(args.file, name.span, "invalid paper name"), + None => bail!(args.source, name.span, "invalid paper name"), paper => paper, }, None => None, diff --git a/src/library/text.rs b/src/library/text.rs index 5973a7e2..cd97691c 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -132,7 +132,7 @@ pub fn lang(_: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { if dir.v.axis() == SpecAxis::Horizontal { Some(dir.v) } else { - bail!(args.file, dir.span, "must be horizontal"); + bail!(args.source, dir.span, "must be horizontal"); } } else { iso.as_deref().map(lang_dir) diff --git a/src/library/utility.rs b/src/library/utility.rs index fb39fce3..3c157ea1 100644 --- a/src/library/utility.rs +++ b/src/library/utility.rs @@ -25,7 +25,7 @@ pub fn len(_: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { Value::Str(v) => Value::Int(v.len() as i64), Value::Array(v) => Value::Int(v.len() as i64), Value::Dict(v) => Value::Int(v.len() as i64), - _ => bail!(args.file, span, "expected string, array or dictionary"), + _ => bail!(args.source, span, "expected string, array or dictionary"), }) } @@ -35,7 +35,7 @@ pub fn rgb(_: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { if let Some(string) = args.eat::<Spanned<EcoString>>() { match RgbaColor::from_str(&string.v) { Ok(color) => color, - Err(_) => bail!(args.file, string.span, "invalid color"), + Err(_) => bail!(args.source, string.span, "invalid color"), } } else { let r = args.expect("red component")?; @@ -60,7 +60,7 @@ pub fn max(_: &mut EvalContext, args: &mut FuncArgs) -> TypResult<Value> { /// Find the minimum or maximum of a sequence of values. fn minmax(args: &mut FuncArgs, goal: Ordering) -> TypResult<Value> { - let &mut FuncArgs { file, span, .. } = args; + let &mut FuncArgs { source, span, .. } = args; let mut extremum = args.expect::<Value>("value")?; for value in args.all::<Value>() { @@ -71,7 +71,7 @@ fn minmax(args: &mut FuncArgs, goal: Ordering) -> TypResult<Value> { } } None => bail!( - file, + source, span, "cannot compare {} with {}", extremum.type_name(), |
