Skip to content

Commit

Permalink
chore: improve error logs while rendering interpolated strings (infin…
Browse files Browse the repository at this point in the history
…yon#3266)

With this change, in case of undefined value, the log will be something like:

```
Error: undefined value at line 1:`hello ${{ some_undefined }}`
```
  • Loading branch information
morenol committed May 19, 2023
1 parent c8315c1 commit 7627bcb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions crates/fluvio-connector-package/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ impl ConfigRenderer {
Ok(rendered) => Ok(rendered),
Err(err) => {
error!(%err, %input, "failed to render");
Err(anyhow::anyhow!("failed to render: `{}`.", input))

let line_id = err.line().unwrap_or(1);
let line_id = std::cmp::max(1, line_id);
let line = input.lines().nth(line_id - 1).unwrap();
Err(anyhow::anyhow!(
"Error: {} at line {}:`{}`",
err.kind(),
line_id,
line,
))
}
}
}
Expand Down Expand Up @@ -167,7 +176,11 @@ mod test {

let renderer = ConfigRenderer::new_with_context_stores(vec![store]).unwrap();
let output = renderer.render_str("hello ${{ some_undefined }}");
assert!(output.is_err());
let err = output.unwrap_err();
assert_eq!(
err.to_string(),
"Error: undefined value at line 1:`hello ${{ some_undefined }}`".to_string()
);
}

#[test]
Expand Down

0 comments on commit 7627bcb

Please sign in to comment.