Skip to content

Commit 80ed13c

Browse files
authored
fix(dart): Throw FormatException as const (#3174)
1 parent db2be83 commit 80ed13c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

internal/sidekick/dart/annotate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func (annotate *annotateModel) createFromJsonLine(field *api.Field, state *api.A
862862
decoder := annotate.decoder(field.Typez, field.TypezID, state)
863863
return fmt.Sprintf(
864864
"switch (%s) { null => %s, List<Object?> $1 => [for (final i in $1) %s(i)], "+
865-
"_ => throw FormatException('\"%s\" is not a list') }",
865+
"_ => throw const FormatException('\"%s\" is not a list') }",
866866
data, defaultValue, decoder, field.JSONName)
867867
case field.Map:
868868
message := state.MessageByID[field.TypezID]
@@ -875,7 +875,7 @@ func (annotate *annotateModel) createFromJsonLine(field *api.Field, state *api.A
875875

876876
return fmt.Sprintf(
877877
"switch (%s) { null => %s, Map<String, Object?> $1 => {for (final e in $1.entries) %s(e.key): %s(e.value)}, "+
878-
"_ => throw FormatException('\"%s\" is not an object') }",
878+
"_ => throw const FormatException('\"%s\" is not an object') }",
879879
data, defaultValue, keyDecoder, valueDecoder, field.JSONName)
880880
}
881881

internal/sidekick/dart/annotate_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -945,28 +945,28 @@ func TestCreateFromJsonLine(t *testing.T) {
945945
// repeated primitives
946946
{
947947
&api.Field{Name: "boolList", JSONName: "boolList", Typez: api.BOOL_TYPE, Repeated: true},
948-
"switch (json['boolList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBool(i)], _ => throw FormatException('\"boolList\" is not a list') }",
948+
"switch (json['boolList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBool(i)], _ => throw const FormatException('\"boolList\" is not a list') }",
949949
}, {
950950
&api.Field{Name: "bytesList", JSONName: "bytesList", Typez: api.BYTES_TYPE, Repeated: true},
951-
"switch (json['bytesList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBytes(i)], _ => throw FormatException('\"bytesList\" is not a list') }",
951+
"switch (json['bytesList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeBytes(i)], _ => throw const FormatException('\"bytesList\" is not a list') }",
952952
}, {
953953
&api.Field{Name: "doubleList", JSONName: "doubleList", Typez: api.DOUBLE_TYPE, Repeated: true},
954-
"switch (json['doubleList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeDouble(i)], _ => throw FormatException('\"doubleList\" is not a list') }",
954+
"switch (json['doubleList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeDouble(i)], _ => throw const FormatException('\"doubleList\" is not a list') }",
955955
}, {
956956
&api.Field{Name: "fixed32List", JSONName: "fixed32List", Typez: api.FIXED32_TYPE, Repeated: true},
957-
"switch (json['fixed32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"fixed32List\" is not a list') }",
957+
"switch (json['fixed32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw const FormatException('\"fixed32List\" is not a list') }",
958958
}, {
959959
&api.Field{Name: "int32List", JSONName: "int32List", Typez: api.INT32_TYPE, Repeated: true},
960-
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"int32List\" is not a list') }",
960+
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw const FormatException('\"int32List\" is not a list') }",
961961
}, {
962962
&api.Field{Name: "stringList", JSONName: "stringList", Typez: api.STRING_TYPE, Repeated: true},
963-
"switch (json['stringList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeString(i)], _ => throw FormatException('\"stringList\" is not a list') }",
963+
"switch (json['stringList']) { null => [], List<Object?> $1 => [for (final i in $1) decodeString(i)], _ => throw const FormatException('\"stringList\" is not a list') }",
964964
},
965965

966966
// repeated primitives w/ optional
967967
{
968968
&api.Field{Name: "int32List_opt", JSONName: "int32List", Typez: api.INT32_TYPE, Repeated: true, Optional: true},
969-
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw FormatException('\"int32List\" is not a list') }",
969+
"switch (json['int32List']) { null => [], List<Object?> $1 => [for (final i in $1) decodeInt(i)], _ => throw const FormatException('\"int32List\" is not a list') }",
970970
},
971971

972972
// enums
@@ -996,7 +996,7 @@ func TestCreateFromJsonLine(t *testing.T) {
996996
{
997997
// Map of bytes.
998998
&api.Field{Name: "message", JSONName: "message", Map: true, Typez: api.MESSAGE_TYPE, TypezID: mapStringToBytes.ID},
999-
"switch (json['message']) { null => {}, Map<String, Object?> $1 => {for (final e in $1.entries) decodeString(e.key): decodeBytes(e.value)}, _ => throw FormatException('\"message\" is not an object') }",
999+
"switch (json['message']) { null => {}, Map<String, Object?> $1 => {for (final e in $1.entries) decodeString(e.key): decodeBytes(e.value)}, _ => throw const FormatException('\"message\" is not an object') }",
10001000
},
10011001
} {
10021002
t.Run(test.field.Name, func(t *testing.T) {

0 commit comments

Comments
 (0)