handleJsonFileErrors function
Handles JSON file content errors: empty, malformed, or wrong root type.
Implementation
void handleJsonFileErrors(String fileContent, String filePath) {
if (fileContent.trim().isEmpty) {
throw SkipFileException('[ERROR] JSON file is empty, skipping: $filePath');
}
try {
final dynamic decoded = jsonDecode(fileContent);
if (decoded is! Map<String, dynamic>) {
throw FormatException('[ERROR] JSON root is not a Map: $filePath');
}
} catch (e) {
if (e is SkipFileException) rethrow;
throw FormatException(
'[ERROR] Failed to parse JSON in file: $filePath\n$e',
);
}
}