-
Notifications
You must be signed in to change notification settings - Fork 4
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
Use named placeholder for error messages in options.proto
#842
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #842 +/- ##
=========================================
Coverage 75.16% 75.16%
Complexity 1178 1178
=========================================
Files 190 190
Lines 4293 4293
Branches 346 346
=========================================
Hits 3227 3227
Misses 935 935
Partials 131 131 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yevhenii-nadtochii LGTM except for some comments.
src/main/proto/spine/options.proto
Outdated
@@ -668,19 +676,14 @@ message IfMissingOption { | |||
// double value = 1 [(min) = { | |||
// value: "0.0", | |||
// exclusive: true, | |||
// error_msg: "Temperature cannot reach {other}K, but provided {value}." | |||
// error_msg: "The temperature cannot reach `{min.threshold}K`, but provided `{field.value}`." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify to {min.value}
.
src/main/proto/spine/options.proto
Outdated
// | ||
option (default_message) = "The number must be greater than %s%s."; | ||
// The default error message. | ||
option (default_message) = "The field `{parent.type}.{field.name}` must be {max.comparison} {min.threshold}."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about {max.operator}
?
src/main/proto/spine/options.proto
Outdated
// 4. `{parent.type}` – the fully qualified name of the field declaring type. | ||
// 5. `{min.threshold}` – the specified minimum threshold `value`. | ||
// 6. `{min.comparison}` – if `exclusive` is set to `true`, this placeholder equals | ||
// to "greater than". Otherwise, "greater than or equal to". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed today, let's use >
and >=
.
@armiol PTAL Though, we still have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yevhenii-nadtochii LGTM.
But what if we define the corresponding behaviour for (distinct)
and (range)
in this PR? It would be easier to review all the proposed placeholder names together.
Please consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments. I'll review it once again after this batch is addressed.
src/main/proto/spine/options.proto
Outdated
// | ||
message IfMissingOption { | ||
|
||
// The default error message. | ||
option (default_message) = "A value must be set."; | ||
option (default_message) = "The field `{parent.type}.{field.name}` of type `{field.type}` must have a value."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it "the type"?
src/main/proto/spine/options.proto
Outdated
// The default error message for the field. | ||
option (default_message) = "The message must have valid properties."; | ||
// The default error message. | ||
option (default_message) = "The field `{parent.type}.{field.path}` of type `{field.type}` is invalid. The field value: `{field.value}`."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we having here field.path
instead of field.name
? We refer to the immediate placement of the field in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the combination of {parent.type}.{field.name}
above.
src/main/proto/spine/options.proto
Outdated
// The default error message used when the field value is re-assigned. | ||
option (default_message) = "The field `{fieldName}` already has the value `{currentValue}` and cannot be reassigned to `{proposedValue}`."; | ||
// The default error message. | ||
option (default_message) = "The field `{parent.type}.{field.name}` of `{field.type}` already has the value `{field.value}` and cannot be reassigned to `{field.proposed_value}`."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have "of the type {field.type}
" instead of "of {field.type}
"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in similar case above and below, please.
@armiol @alexander-yevsyukov PTAL The two remaining options have got the default and custom messages support:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yevhenii-nadtochii LGTM in general. Please see my comments.
src/main/proto/spine/options.proto
Outdated
message IfHasDuplicatesOption { | ||
|
||
// The default error message. | ||
option (default_message) = "The field `{parent.type}.{field.name}` of the type `{field.type}` must not contain duplicates. The found duplicates: `{field.duplicates}`."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The duplicates found:"
src/main/proto/spine/options.proto
Outdated
// | ||
// message Blizzard { | ||
// repeated Snowflake = 1 [(distinct) = true, | ||
// (if_has_duplicates).error_msg = "Every snowflake must be unique! The found duplicates: `{field.duplicates}`."]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/main/proto/spine/options.proto
Outdated
// 1. `{field.name}` – the field name. | ||
// 2. `{field.type}` – the fully qualified name of the field type. | ||
// 3. `{field.value}` – the field value (the whole collection). | ||
// 4. `{field.duplicates}` – the found duplicates (elements that occur more than once). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/main/proto/spine/options.proto
Outdated
// double angle = 4 [(range).value = "(0.0..180.0)"]; | ||
// } | ||
// | ||
// NOTE: That definition of ranges must be consistent with the type they constrain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say "... they limit", or "... they describe".
src/main/proto/spine/options.proto
Outdated
// (if_invalid).error_msg = "The field is invalid."]; | ||
// } | ||
// It is applicable only to message fields marked with `(validate)`. | ||
// Repeated fields are supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about map
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@armiol PTAL I've updated docs to |
This PR unifies error messages format for all Spine options. Previously, the default error messages used
printf
-style format, but the custom ones expected placeholders instead. Now, both the custom and the default messages expect a string, which may contain placeholders in an arbitrary order.A number of placeholders have been increased to allow specifying more detailed errors.