Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checked_yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.0.4-wip
## 2.0.4

- Require Dart 3.8

Expand Down
66 changes: 30 additions & 36 deletions checked_yaml/lib/checked_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,29 @@ ParsedYamlException toParsedYamlException(
)
as YamlNode;
return ParsedYamlException(exception.message!, node, innerError: exception);
} else {
if (exception.key == null) {
return ParsedYamlException(
exception.message ?? 'There was an error parsing the map.',
yamlMap,
innerError: exception,
);
} else if (!yamlMap.containsKey(exception.key)) {
return ParsedYamlException(
[
'Missing key "${exception.key}".',
if (exception.message != null) exception.message!,
].join(' '),
yamlMap,
innerError: exception,
);
} else {
var message = 'Unsupported value for "${exception.key}".';
if (exception.message != null) {
message = '$message ${exception.message}';
}
return ParsedYamlException(
message,
yamlMap.nodes[exception.key] ?? yamlMap,
innerError: exception,
);
}
}

if (exception.key == null) {
return ParsedYamlException(
exception.message ?? 'There was an error parsing the map.',
yamlMap,
innerError: exception,
);
}

if (!yamlMap.containsKey(exception.key)) {
return ParsedYamlException(
['Missing key "${exception.key}".', ?exception.message].join(' '),
yamlMap,
innerError: exception,
);
}

return ParsedYamlException(
['Unsupported value for "${exception.key}".', ?exception.message].join(' '),
yamlMap.nodes[exception.key] ?? yamlMap,
innerError: exception,
);
}

/// An exception thrown when parsing YAML that contains information about the
Expand All @@ -118,12 +113,14 @@ class ParsedYamlException implements Exception {
/// contains the source error object.
final Object? innerError;

ParsedYamlException(String message, YamlNode this.yamlNode, {this.innerError})
: // TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed!
message = message.replaceAll(" of ' in type cast'", ' in type cast');
const ParsedYamlException(
this.message,
YamlNode this.yamlNode, {
this.innerError,
});

factory ParsedYamlException.fromYamlException(YamlException exception) =>
_WrappedYamlException(exception);
factory ParsedYamlException.fromYamlException(YamlException exception) =
_WrappedYamlException;

/// Returns [message] formatted with source information provided by
/// [yamlNode].
Expand All @@ -134,7 +131,7 @@ class ParsedYamlException implements Exception {
}

class _WrappedYamlException implements ParsedYamlException {
_WrappedYamlException(this.innerError);
const _WrappedYamlException(this.innerError);

@override
String? get formattedMessage => innerError.span?.message(innerError.message);
Expand All @@ -147,7 +144,4 @@ class _WrappedYamlException implements ParsedYamlException {

@override
YamlNode? get yamlNode => null;

@override
String toString() => 'ParsedYamlException: $formattedMessage';
}
2 changes: 1 addition & 1 deletion checked_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: checked_yaml
version: 2.0.4-wip
version: 2.0.4

description: >-
Generate more helpful exceptions when decoding YAML documents using
Expand Down