Handle missing references

This commit is contained in:
Tom Alexander 2020-04-12 21:26:23 -04:00
parent fe32edbc28
commit 24d2c1831c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1 @@
{"rank": "Admiral"}

View File

@ -0,0 +1 @@
Hello {name}!

View File

@ -87,8 +87,13 @@ impl<'a> DustRenderer<'a> {
match tag { match tag {
DustTag::DTComment(_comment) => (), DustTag::DTComment(_comment) => (),
DustTag::DTReference(reference) => { DustTag::DTReference(reference) => {
let val = walk_path(context, &reference.path.keys)?; let val = walk_path(context, &reference.path.keys);
return val.render(); if let Err(RenderError::WontWalk { .. }) = val {
// If reference does not exist in the context, it becomes an empty string
return Ok("".to_owned());
} else {
return val?.render();
}
} }
_ => (), // TODO: Implement the rest _ => (), // TODO: Implement the rest
} }