[authored by Randal, assisted by Gemini]
Problem
In packages/kaisel_core/lib/src/kaisel_router.dart, the helper function kaiselOriginFrames captures and parses the stringified representation of a StackTrace using a regular expression (_frameLocation) to resolve file paths, lines, and columns for DevTools support:
https://github.com/Mastersam07/kaisel/blob/dev/packages/kaisel_core/lib/src/kaisel_router.dart#L38-L58
Relying on manual RegExp parsing of StackTrace.toString() is highly fragile:
- Stack trace string formats are not guaranteed stable by the Dart SDK.
- The format differs significantly depending on the platform/compiler (Dart VM vs. JS vs. WebAssembly).
- Any updates to the compiler output or SDK changes can silently break DevTools frame location resolution.
Proposed Solution
Migrate stack trace processing to the official, Dart-team-maintained package:stack_trace which is built precisely to parse, normalize, and format stack traces reliably across VM and web platforms.
Proposed Implementation:
- Add
stack_trace as a dependency in packages/kaisel_core/pubspec.yaml.
- Refactor
kaiselOriginFrames to construct a Trace and filter/map its frames:
import 'package:stack_trace/stack_trace.dart';
List<KaiselOriginFrame> kaiselOriginFrames(StackTrace? trace, {int limit = 5}) {
if (trace == null) return const [];
final frames = <KaiselOriginFrame>[];
final parsedTrace = Trace.from(trace);
for (final frame in parsedTrace.frames) {
final uriStr = frame.uri.toString();
// Filter out framework and SDK frames
if (uriStr.startsWith('dart:') ||
uriStr.startsWith('package:kaisel/') ||
uriStr.startsWith('package:kaisel_core/') ||
uriStr.startsWith('package:flutter/')) {
continue;
}
frames.add(
KaiselOriginFrame(
display: frame.toString(),
uri: uriStr,
line: frame.line,
column: frame.column,
),
);
if (frames.length >= limit) break;
}
return frames;
}
[authored by Randal, assisted by Gemini]
Problem
In
packages/kaisel_core/lib/src/kaisel_router.dart, the helper functionkaiselOriginFramescaptures and parses the stringified representation of aStackTraceusing a regular expression (_frameLocation) to resolve file paths, lines, and columns for DevTools support:https://github.com/Mastersam07/kaisel/blob/dev/packages/kaisel_core/lib/src/kaisel_router.dart#L38-L58
Relying on manual RegExp parsing of
StackTrace.toString()is highly fragile:Proposed Solution
Migrate stack trace processing to the official, Dart-team-maintained
package:stack_tracewhich is built precisely to parse, normalize, and format stack traces reliably across VM and web platforms.Proposed Implementation:
stack_traceas a dependency inpackages/kaisel_core/pubspec.yaml.kaiselOriginFramesto construct aTraceand filter/map its frames: