@@ -158,6 +158,9 @@ extend google.protobuf.FieldOptions {
158
158
//
159
159
// Once set, the `id` field cannot be changed.
160
160
//
161
+ // Use `(if_set_again).error_msg` option to specify a custom error message that will be shown
162
+ // on attempt to re-assign the field value.
163
+ //
161
164
bool set_once = 73824 ;
162
165
163
166
// The option to mark a `repeated` field as a collection of unique elements.
@@ -267,7 +270,10 @@ extend google.protobuf.FieldOptions {
267
270
//
268
271
bool column = 73854 ;
269
272
270
- // See `IfSetAgainOption`.
273
+ // Defines the error message used if a `set_once` field is set again.
274
+ //
275
+ // Applies only to the fields marked as `set_once`.
276
+ //
271
277
IfSetAgainOption if_set_again = 73855 ;
272
278
273
279
// Reserved 73856 to 73890 for future options.
@@ -1011,18 +1017,26 @@ message CompareByOption {
1011
1017
//
1012
1018
// Applies only to the fields marked as `set_once`.
1013
1019
//
1014
- // Example: Using the `(set_once)` option.
1015
- //
1016
- // message User {
1017
- // UserId id = 1 [(set_once) = true,
1018
- // (if_set_again).error_msg = "The student ID cannot be re-assigned."];
1019
- // }
1020
- //
1021
1020
message IfSetAgainOption {
1022
1021
1023
- // The default error message for the field.
1024
- option (default_message) = "The field value cannot be re-assigned." ;
1022
+ // The default error message used when the field is re-assigned .
1023
+ option (default_message) = "The field `{fieldName}` cannot be re-assigned." ;
1025
1024
1026
- // A user-defined error message.
1025
+ // A user-defined error message pattern.
1026
+ //
1027
+ // The specified message may include the following tokens:
1028
+ // 1. `{fieldName}` — the field name.
1029
+ // 2. `{currentValue}` — the field's current value.
1030
+ // 3. `{newValue} — the field's new value.
1031
+ //
1032
+ // The tokens will be replaced at runtime when the error is constructed.
1033
+ //
1034
+ // Example: Using the `(set_once)` option.
1035
+ //
1036
+ // message User {
1037
+ // UserId id = 1 [(set_once) = true,
1038
+ // (if_set_again).error_msg = "The student ID cannot be re-assigned. The suggested value: `{newValue}`."];
1039
+ // }
1040
+ //
1027
1041
string error_msg = 1 ;
1028
1042
}
0 commit comments