Skip to content

Commit b2fee98

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Improve error reporting when reading messages.yaml files.
Changes the format of the exceptions thrown by `decodeCfeStyleMessagesYaml` so that if a problem occurs while reading `pkg/front_end/messages.yaml` or `pkg/_fe_analyzer_shared/messages.yaml`, the path to the file with the problem is reported. Change-Id: I6a6a69648b6d59cefa3f7582b3c6d13b7c8a523c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449924 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent a3bd2ad commit b2fee98

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/analyzer_utilities/lib/messages.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ String convertTemplate(Map<String, int> placeholderToIndexMap, String entry) {
8585
Map<String, T> decodeCfeStyleMessagesYaml<T extends CfeStyleErrorCodeInfo>(
8686
Object? yaml, {
8787
required T Function(YamlMap) decodeMessage,
88+
required String path,
8889
}) {
8990
Never problem(String message) {
90-
throw 'Problem in pkg/front_end/messages.yaml: $message';
91+
throw 'Problem in $path: $message';
9192
}
9293

9394
var result = <String, T>{};
@@ -106,7 +107,10 @@ Map<String, T> decodeCfeStyleMessagesYaml<T extends CfeStyleErrorCodeInfo>(
106107
try {
107108
result[errorName] = decodeMessage(errorValue);
108109
} catch (e, st) {
109-
Error.throwWithStackTrace('while processing $errorName, $e', st);
110+
Error.throwWithStackTrace(
111+
'while processing $errorName from $path, $e',
112+
st,
113+
);
110114
}
111115
}
112116
return result;
@@ -122,7 +126,11 @@ Map<String, T> _loadCfeStyleMessages<T extends CfeStyleErrorCodeInfo>(
122126
File(path).readAsStringSync(),
123127
sourceUrl: Uri.file(path),
124128
);
125-
return decodeCfeStyleMessagesYaml(messagesYaml, decodeMessage: decodeMessage);
129+
return decodeCfeStyleMessagesYaml(
130+
messagesYaml,
131+
decodeMessage: decodeMessage,
132+
path: path,
133+
);
126134
}
127135

128136
/// Splits [text] on spaces using the given [maxWidth] (and [firstLineWidth] if

0 commit comments

Comments
 (0)