Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't 500 if search attribute is invalid #925

Merged
merged 1 commit into from
Sep 15, 2016

Conversation

tduffield
Copy link
Contributor

@tduffield tduffield commented Sep 6, 2016

In the case where a user, when providing a search, provides an attribute
constraint (-a flag) that is invalid, we currently throw a 500. An
invalid attribute constraint most commonly is specifying a nested hash
using dot-notation when one or more values in that constraint are, in
fact, not a hash. This change prevents the system from throwing a 500
and presents the user with a more correct result.

For example, knife search node "*:*" -a uptime.seconds is invalid
because the key 'uptime' does exist but it is a string, not a
hash. Thus, ej attempts to fetch the key 'seconds' from that string,
throwing an error within ej for an invalid function clause. With this change,
we simply return "ERROR - Attribute does not exist".

The reason there are no tests is that there isn't a great way to test this code path as it is a private function nested inside several helpers. The time it would take to setup mocks to exercise this code path likely isn't worth the time given how easily this is to replicate manually.

%% key, typically trying to access a value as a hash that is actually
%% a string (i.e. uptime.seconds)
error:function_clause -> null;
Error:Reason -> {Error, Reason}
Copy link
Member

@marcparadise marcparadise Sep 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the term that comes back can't be converted as ejson -> json, we'll still end up with a 500 as we prepare the body response. Maybe a generic error string for the return value in that case - or just 'null' - , and use error_loggerto capture the details.

@tduffield tduffield force-pushed the SPOOL-319/dont-500-on-invalid-attribute branch from c19cb94 to c029b86 Compare September 7, 2016 15:03
@marcparadise
Copy link
Member

👍

In the case where a user, when providing a search, provides an attribute
constraint (-a flag) that is invalid, we currently throw a 500. An
invalid attribute constraint most commonly is specifying a nested hash
using dot-notation when one or more values in that constraint are, in
fact, not a hash. This change prevents the system from throwing a 500
and presents the user with a message indicating that the attribute does
not exist.

For example, `knife search node "*:*" -a uptime.seconds` is invalid
because the key `'uptime'` does exist but it is a string, not a
hash. Thus, ej attempts to fetch the key `'seconds'` from that string,
throwing an error within ej for an invalid function clause. With this
change, the search will return "ERROR - Attribute does not exist".

Signed-off-by: Tom Duffield <[email protected]>
@marcparadise marcparadise force-pushed the SPOOL-319/dont-500-on-invalid-attribute branch from c029b86 to cecf0fa Compare September 15, 2016 21:38
@marcparadise marcparadise merged commit 608dbe9 into master Sep 15, 2016
@marcparadise marcparadise deleted the SPOOL-319/dont-500-on-invalid-attribute branch September 15, 2016 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants