|
@@ -18,7 +18,9 @@ use cargo_mobile2::{
|
|
|
relativize_path,
|
|
|
},
|
|
|
};
|
|
|
-use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
|
|
|
+use handlebars::{
|
|
|
+ Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError, RenderErrorReason,
|
|
|
+};
|
|
|
|
|
|
use std::{
|
|
|
env::{current_dir, var, var_os},
|
|
@@ -299,7 +301,9 @@ fn join(
|
|
|
out
|
|
|
.write(
|
|
|
&get_str_array(helper, |s| s.to_string())
|
|
|
- .ok_or_else(|| RenderError::new("`join` helper wasn't given an array"))?
|
|
|
+ .ok_or_else(|| {
|
|
|
+ RenderErrorReason::ParamTypeMismatchForName("join", "0".to_owned(), "array".to_owned())
|
|
|
+ })?
|
|
|
.join(", "),
|
|
|
)
|
|
|
.map_err(Into::into)
|
|
@@ -315,7 +319,13 @@ fn quote_and_join(
|
|
|
out
|
|
|
.write(
|
|
|
&get_str_array(helper, |s| format!("{s:?}"))
|
|
|
- .ok_or_else(|| RenderError::new("`quote-and-join` helper wasn't given an array"))?
|
|
|
+ .ok_or_else(|| {
|
|
|
+ RenderErrorReason::ParamTypeMismatchForName(
|
|
|
+ "quote-and-join",
|
|
|
+ "0".to_owned(),
|
|
|
+ "array".to_owned(),
|
|
|
+ )
|
|
|
+ })?
|
|
|
.join(", "),
|
|
|
)
|
|
|
.map_err(Into::into)
|
|
@@ -332,7 +342,11 @@ fn quote_and_join_colon_prefix(
|
|
|
.write(
|
|
|
&get_str_array(helper, |s| format!("{:?}", format!(":{s}")))
|
|
|
.ok_or_else(|| {
|
|
|
- RenderError::new("`quote-and-join-colon-prefix` helper wasn't given an array")
|
|
|
+ RenderErrorReason::ParamTypeMismatchForName(
|
|
|
+ "quote-and-join-colon-prefix",
|
|
|
+ "0".to_owned(),
|
|
|
+ "array".to_owned(),
|
|
|
+ )
|
|
|
})?
|
|
|
.join(", "),
|
|
|
)
|
|
@@ -381,12 +395,14 @@ fn app_root(ctx: &Context) -> Result<&str, RenderError> {
|
|
|
let app_root = ctx
|
|
|
.data()
|
|
|
.get("app")
|
|
|
- .ok_or_else(|| RenderError::new("`app` missing from template data."))?
|
|
|
+ .ok_or_else(|| RenderErrorReason::Other("`app` missing from template data.".to_owned()))?
|
|
|
.get("root-dir")
|
|
|
- .ok_or_else(|| RenderError::new("`app.root-dir` missing from template data."))?;
|
|
|
- app_root
|
|
|
- .as_str()
|
|
|
- .ok_or_else(|| RenderError::new("`app.root-dir` contained invalid UTF-8."))
|
|
|
+ .ok_or_else(|| {
|
|
|
+ RenderErrorReason::Other("`app.root-dir` missing from template data.".to_owned())
|
|
|
+ })?;
|
|
|
+ app_root.as_str().ok_or_else(|| {
|
|
|
+ RenderErrorReason::Other("`app.root-dir` contained invalid UTF-8.".to_owned()).into()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
fn prefix_path(
|
|
@@ -401,8 +417,8 @@ fn prefix_path(
|
|
|
util::prefix_path(app_root(ctx)?, get_str(helper))
|
|
|
.to_str()
|
|
|
.ok_or_else(|| {
|
|
|
- RenderError::new(
|
|
|
- "Either the `app.root-dir` or the specified path contained invalid UTF-8.",
|
|
|
+ RenderErrorReason::Other(
|
|
|
+ "Either the `app.root-dir` or the specified path contained invalid UTF-8.".to_owned(),
|
|
|
)
|
|
|
})?,
|
|
|
)
|
|
@@ -420,12 +436,14 @@ fn unprefix_path(
|
|
|
.write(
|
|
|
util::unprefix_path(app_root(ctx)?, get_str(helper))
|
|
|
.map_err(|_| {
|
|
|
- RenderError::new("Attempted to unprefix a path that wasn't in the app root dir.")
|
|
|
+ RenderErrorReason::Other(
|
|
|
+ "Attempted to unprefix a path that wasn't in the app root dir.".to_owned(),
|
|
|
+ )
|
|
|
})?
|
|
|
.to_str()
|
|
|
.ok_or_else(|| {
|
|
|
- RenderError::new(
|
|
|
- "Either the `app.root-dir` or the specified path contained invalid UTF-8.",
|
|
|
+ RenderErrorReason::Other(
|
|
|
+ "Either the `app.root-dir` or the specified path contained invalid UTF-8.".to_owned(),
|
|
|
)
|
|
|
})?,
|
|
|
)
|