Improve error message when request contains the wrong type of placeholder

This commit is contained in:
Louis Dureuil 2025-07-02 11:35:44 +02:00
parent ede456c5b0
commit f6287602e9
No known key found for this signature in database

View file

@ -561,6 +561,7 @@ impl Request {
Err(error) => { Err(error) => {
let message = let message =
error.error_message("request", REQUEST_PLACEHOLDER, REPEAT_PLACEHOLDER); error.error_message("request", REQUEST_PLACEHOLDER, REPEAT_PLACEHOLDER);
let message = format!("{message}\n - Note: this template is using a document template, and so expects to contain the placeholder {REQUEST_PLACEHOLDER:?} rather than {REQUEST_FRAGMENT_PLACEHOLDER:?}");
return Err(NewEmbedderError::rest_could_not_parse_template(message)); return Err(NewEmbedderError::rest_could_not_parse_template(message));
} }
}; };
@ -592,15 +593,23 @@ impl RequestFromFragments {
request: Value, request: Value,
search_fragments: impl IntoIterator<Item = (String, Value)>, search_fragments: impl IntoIterator<Item = (String, Value)>,
) -> Result<Self, NewEmbedderError> { ) -> Result<Self, NewEmbedderError> {
let request = let request = match InjectableValue::new(
match InjectableValue::new(request, REQUEST_FRAGMENT_PLACEHOLDER, REPEAT_PLACEHOLDER) { request,
Ok(template) => template, REQUEST_FRAGMENT_PLACEHOLDER,
Err(error) => { REPEAT_PLACEHOLDER,
let message = ) {
error.error_message("request", REQUEST_PLACEHOLDER, REPEAT_PLACEHOLDER); Ok(template) => template,
return Err(NewEmbedderError::rest_could_not_parse_template(message)); Err(error) => {
} let message = error.error_message(
}; "request",
REQUEST_FRAGMENT_PLACEHOLDER,
REPEAT_PLACEHOLDER,
);
let message = format!("{message}\n - Note: this template is using fragments, and so expects to contain the placeholder {REQUEST_FRAGMENT_PLACEHOLDER:?} rathern than {REQUEST_PLACEHOLDER:?}");
return Err(NewEmbedderError::rest_could_not_parse_template(message));
}
};
let search_fragments: Result<_, NewEmbedderError> = search_fragments let search_fragments: Result<_, NewEmbedderError> = search_fragments
.into_iter() .into_iter()