Mastersam07 / Mastersam07/kaisel

refactor: replace fragile StackTrace RegExp parsing with package:stack_trace

Open
#52 1 comment 0 reactions 1 assignee View on GitHub

@Mastersam07 is already working on this.

Since Jul 20, 2026.

contributions welcome enhancement pkg:kaisel_core
Dominant language
Dart
Stars
69
Forks
2
Avg merge
18m
Merged PRs (30d)
9

Description

[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`](https://pub.dev/packages/stack_trace) which is built precisely to parse, normalize, and format stack traces reliably across VM and web platforms.

### Proposed Implementation:
1. Add `stack_trace` as a dependency in `packages/kaisel_core/pubspec.yaml`.
2. Refactor `kaiselOriginFrames` to construct a `Trace` and filter/map its frames:

```dart
import 'package:stack_trace/stack_trace.dart';

List kaiselOriginFrames(StackTrace? trace, {int limit = 5}) {
if (trace == null) return const [];

final frames = [];
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;
}
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.