Skip to content

Commit

Permalink
Improve message handling in validate_criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
vilhalmer authored and emersion committed May 3, 2021
1 parent 80d4f82 commit f31f682
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,22 +487,25 @@ struct mako_criteria *create_criteria_from_notification(
// To keep the behavior of criteria predictable, there are a few rules that we
// have to impose on what can be modified depending on what was matched.
bool validate_criteria(struct mako_criteria *criteria) {
char * invalid_option = NULL;

if (criteria->spec.grouped ||
criteria->spec.group_index ||
criteria->spec.output ||
criteria->spec.anchor) {
static const char *message =
"Setting `%s` is not allowed when matching `grouped`, "
"`group-index`, `output`, or `anchor`\n";

if (criteria->style.spec.anchor) {
fprintf(stderr, message, "anchor");
return false;
invalid_option = "anchor";
} else if (criteria->style.spec.output) {
fprintf(stderr, message, "output");
return false;
invalid_option = "output";
} else if (criteria->style.spec.group_criteria_spec) {
fprintf(stderr, message, "group-by");
invalid_option = "group-by";
}

if (invalid_option) {
fprintf(stderr,
"Setting `%s` is not allowed when matching `grouped`, "
"`group-index`, `output`, or `anchor`\n",
invalid_option);
return false;
}
}
Expand Down Expand Up @@ -539,19 +542,20 @@ bool validate_criteria(struct mako_criteria *criteria) {

if (criteria->style.spec.group_criteria_spec) {
struct mako_criteria_spec *spec = &criteria->style.group_criteria_spec;
static const char *message = "`%s` cannot be used in `group-by`\n";

if (spec->group_index) {
fprintf(stderr, message, "group-index");
return false;
invalid_option = "group-index";
} else if (spec->grouped) {
fprintf(stderr, message, "grouped");
return false;
invalid_option = "grouped";
} else if (spec->anchor) {
fprintf(stderr, message, "anchor");
return false;
invalid_option = "anchor";
} else if (spec->output) {
fprintf(stderr, message, "output");
invalid_option = "output";
}

if (invalid_option) {
fprintf(stderr, "`%s` cannot be used in `group-by`\n",
invalid_option);
return false;
}
}
Expand Down

0 comments on commit f31f682

Please sign in to comment.