parseStackTrace method
Implementation
Map<String, dynamic> parseStackTrace(StackTrace stackTrace) {
final Map<String, dynamic> frames = {};
final lines = stackTrace.toString().split('\n');
// Add the first frame as raw error message
frames['frame_0'] = {
'raw': lines.first.trim(),
};
for (var i = 1; i < lines.length; i++) {
final line = lines[i].trim();
if (line.isEmpty) continue;
// Try to parse detailed frame information
final detailedMatch = RegExp(r'#\d+\s+(\w+)\.?(\w+)?\s+\((.*?):(\d+)(?::\d+)?\)').firstMatch(line);
if (detailedMatch != null) {
final className = detailedMatch.group(1);
final functionName = detailedMatch.group(2);
final file = detailedMatch.group(3);
final lineNum = int.tryParse(detailedMatch.group(4) ?? '0');
frames['frame_$i'] = {
'file': file,
'line': lineNum,
'type': '.',
'class': className,
'function': functionName,
};
} else {
// Fallback to raw format
frames['frame_$i'] = {
'raw': line,
};
}
}
return frames;
}