@@ -36,7 +36,6 @@ T checkedYamlDecode<T>(
3636 if (yaml is YamlMap ) {
3737 map = yaml;
3838 } else if (allowNull && yaml is YamlScalar && yaml.value == null ) {
39- // TODO: test this case!
4039 map = null ;
4140 } else {
4241 throw ParsedYamlException ('Not a map' , yaml);
@@ -73,34 +72,29 @@ ParsedYamlException toParsedYamlException(
7372 )
7473 as YamlNode ;
7574 return ParsedYamlException (exception.message! , node, innerError: exception);
76- } else {
77- if (exception.key == null ) {
78- return ParsedYamlException (
79- exception.message ?? 'There was an error parsing the map.' ,
80- yamlMap,
81- innerError: exception,
82- );
83- } else if (! yamlMap.containsKey (exception.key)) {
84- return ParsedYamlException (
85- [
86- 'Missing key "${exception .key }".' ,
87- if (exception.message != null ) exception.message! ,
88- ].join (' ' ),
89- yamlMap,
90- innerError: exception,
91- );
92- } else {
93- var message = 'Unsupported value for "${exception .key }".' ;
94- if (exception.message != null ) {
95- message = '$message ${exception .message }' ;
96- }
97- return ParsedYamlException (
98- message,
99- yamlMap.nodes[exception.key] ?? yamlMap,
100- innerError: exception,
101- );
102- }
10375 }
76+
77+ if (exception.key == null ) {
78+ return ParsedYamlException (
79+ exception.message ?? 'There was an error parsing the map.' ,
80+ yamlMap,
81+ innerError: exception,
82+ );
83+ }
84+
85+ if (! yamlMap.containsKey (exception.key)) {
86+ return ParsedYamlException (
87+ ['Missing key "${exception .key }".' , ? exception.message].join (' ' ),
88+ yamlMap,
89+ innerError: exception,
90+ );
91+ }
92+
93+ return ParsedYamlException (
94+ ['Unsupported value for "${exception .key }".' , ? exception.message].join (' ' ),
95+ yamlMap.nodes[exception.key] ?? yamlMap,
96+ innerError: exception,
97+ );
10498}
10599
106100/// An exception thrown when parsing YAML that contains information about the
@@ -118,12 +112,10 @@ class ParsedYamlException implements Exception {
118112 /// contains the source error object.
119113 final Object ? innerError;
120114
121- ParsedYamlException (String message, YamlNode this .yamlNode, {this .innerError})
122- : // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed!
123- message = message.replaceAll (" of ' in type cast'" , ' in type cast' );
115+ ParsedYamlException (this .message, YamlNode this .yamlNode, {this .innerError});
124116
125- factory ParsedYamlException .fromYamlException (YamlException exception) =>
126- _WrappedYamlException (exception) ;
117+ factory ParsedYamlException .fromYamlException (YamlException exception) =
118+ _WrappedYamlException ;
127119
128120 /// Returns [message] formatted with source information provided by
129121 /// [yamlNode] .
@@ -147,7 +139,4 @@ class _WrappedYamlException implements ParsedYamlException {
147139
148140 @override
149141 YamlNode ? get yamlNode => null ;
150-
151- @override
152- String toString () => 'ParsedYamlException: $formattedMessage ' ;
153142}
0 commit comments