Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
include:
- runs-on: ubuntu-22.04
architecture: linux-amd64
- runs-on: macos-13
- runs-on: macos-14
architecture: osx-amd64
- runs-on: windows-2019
- runs-on: windows-2022
architecture: windows-amd64
- runs-on: ubuntu-22.04-arm
architecture: linux-arm64
Expand All @@ -30,7 +30,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Build
run: |
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: mv target/release/t_renderer${{ steps.ext.outputs.ext }} t_renderer${{ steps.tag.outputs.tag }}-${{ matrix.architecture }}${{ steps.ext.outputs.ext }}

- name: Upload t_renderer Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: t_renderer${{ steps.tag.outputs.tag }}-${{ matrix.architecture }}${{ steps.ext.outputs.ext }}
path: t_renderer${{ steps.tag.outputs.tag }}-${{ matrix.architecture }}${{ steps.ext.outputs.ext }}
Expand Down
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "t_renderer"
version = "0.2.0"
version = "0.2.1"
authors = ["acados authors"]
edition = "2018"

Expand Down
42 changes: 37 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@ struct Args {
out_file: String
}

fn main() -> io::Result<()> {
fn extract_key_with_prefix(msg: &str, prefix: &str) -> Option<String> {
msg.split(prefix)
.nth(1)
.and_then(|s| s.split('`').next())
.filter(|s| !s.is_empty())
.map(String::from)
}

fn extract_missing_context_key(render_error: &tera::Error) -> Option<String> {
let detailed_error = format!("{:#}", render_error);
extract_key_with_prefix(&detailed_error, "Variable `")
.or_else(|| extract_key_with_prefix(&detailed_error, "Field `"))
.or_else(|| {
let debug_error = format!("{:?}", render_error);
extract_key_with_prefix(&debug_error, "Variable `")
.or_else(|| extract_key_with_prefix(&debug_error, "Field `"))
})
}

fn main() -> io::Result<()> {
// read command line arguments
let args = Args::parse();

Expand All @@ -41,14 +60,21 @@ fn main() -> io::Result<()> {
// println!("{}", contents);

// Parse the string of data into serde_json::Value.
let v: serde_json::Value = serde_json::from_str(&contents)?;
let v: serde_json::Value = serde_json::from_str(&contents).map_err(|e| {
io::Error::new(io::ErrorKind::InvalidData, format!("Invalid JSON context: {}", e))
})?;
// Convert serde_json::Value to tera::Context
let ctx: Context = Context::from_serialize(&v).unwrap();
let ctx: Context = Context::from_serialize(&v).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Failed to build template context from JSON: {}", e),
)
})?;

let tera = match Tera::new(template_glob) {
Ok(t) => t,
Err(e) => {
println!("Parsing error(s): {}", e);
eprintln!("Template parsing error(s): {}", e);
::std::process::exit(1);
}
};
Expand All @@ -59,7 +85,13 @@ fn main() -> io::Result<()> {
f_out.write_all(s.as_bytes())?;
},
Err(e) => {
println!("Error: {}", e);
if let Some(missing_key) = extract_missing_context_key(&e) {
eprintln!(
"Error: missing context value `{}` required by template `{}`.",
missing_key, template_file
);
}
eprintln!("Render error: {}", e);
process::exit(1);
}
};
Expand Down
Loading