mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Merge #461
461: Add a new error message when the `valid_fields` is empty r=curquiza a=brunoocasali I've created a test case to handle the new error formatting behavior, but I'm not sure if: - this is the right place to add the test? - this is the best way to test this behavior? And I'm not sure also regarding the `match` implementation, is this something required? Or maybe just an `if` statement is ok as well? I left the two messages literally without "reusing the prefix" in the implementation because I think this could help the "searchability" of the error in the future. # Pull Request ## What does this PR do? Fixes https://github.com/meilisearch/meilisearch/issues/2140 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [ ] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
This commit is contained in:
commit
a8d28e364d
@ -256,12 +256,21 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco
|
||||
Self::InvalidSortableAttribute { field, valid_fields } => {
|
||||
let valid_names =
|
||||
valid_fields.iter().map(AsRef::as_ref).collect::<Vec<_>>().join(", ");
|
||||
|
||||
if valid_names.is_empty() {
|
||||
write!(
|
||||
f,
|
||||
"Attribute `{}` is not sortable. This index does not have configured sortable attributes.",
|
||||
field
|
||||
)
|
||||
} else {
|
||||
write!(
|
||||
f,
|
||||
"Attribute `{}` is not sortable. Available sortable attributes are: `{}`.",
|
||||
field, valid_names
|
||||
)
|
||||
}
|
||||
}
|
||||
Self::SortRankingRuleMissing => f.write_str(
|
||||
"The sort ranking rule must be specified in the \
|
||||
ranking rules settings to use the sort parameter at search time.",
|
||||
@ -320,3 +329,19 @@ impl fmt::Display for SerializationError {
|
||||
}
|
||||
|
||||
impl StdError for SerializationError {}
|
||||
|
||||
#[test]
|
||||
fn conditionally_lookup_for_error_message() {
|
||||
let prefix = "Attribute `name` is not sortable.";
|
||||
let messages = vec![
|
||||
(BTreeSet::new(), "This index does not have configured sortable attributes."),
|
||||
(BTreeSet::from(["age".to_string()]), "Available sortable attributes are: `age`."),
|
||||
];
|
||||
|
||||
for (list, suffix) in messages {
|
||||
let err =
|
||||
UserError::InvalidSortableAttribute { field: "name".to_string(), valid_fields: list };
|
||||
|
||||
assert_eq!(err.to_string(), format!("{} {}", prefix, suffix));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user