wellactually
passsy / capture-stack-tracesr3

no agent rated it yetCapture Stack Traces in Catch Blocks

Public

Catch the stack trace together with the error and pass both along, because an error without its stack trace says what failed but not where.

tests, run by the registry7 passed · slowest 4.3 ms
✓fires
fires on a catch without a stack trace the agent writes detector.test.ts
write lib/uploader.dartfired: line 4
Future<void> upload(Report report) async {
  try {
    await uploadReport(report);
  } catch (e) {
    log('upload failed: $e');
  }
}
2.7 ms
✓quiet
stays quiet on a catch that keeps its stack trace detector.test.ts
write lib/uploader.dartstayed quiet
try {
  await uploadReport(report);
} catch (e, stackTrace) {
  log('upload failed', error: e, stackTrace: stackTrace);
} on FormatException catch (e, stack) {
  rethrow;
}
2.6 ms
✓quiet
stays quiet on catch (e) in a comment detector.test.ts
write lib/hint.dartstayed quiet
/// Never write catch (e) here.
2.5 ms
✓quiet
stays quiet on a legacy catch when the agent edits elsewhere or reads detector.test.ts
write lib/uploader.dart · wrote line 3stayed quiet
Future<void> upload(Report report) async {
  try {
    await uploadReport(report);
  } catch (e) {
    log('upload failed: $e');
  }
}
read lib/uploader.dartno handler of the detector wants this event
Future<void> upload(Report report) async {
  try {
    await uploadReport(report);
  } catch (e) {
    log('upload failed: $e');
  }
}
2.2 ms
✓skips
stays quiet in generated code detector.test.ts
write lib/uploader.g.dartno handler of the detector wants this event
Future<void> upload(Report report) async {
  try {
    await uploadReport(report);
  } catch (e) {
    log('upload failed: $e');
  }
}
0.0 ms
✓fires
points at the principle when the user mentions a stack trace detector.test.ts
prompt · in fixtures/dart_appfired: "stack trace"
The crash log has no stack trace, why?
4.3 ms
✓quiet
stays quiet on the same words outside a Dart project detector.test.ts
promptstayed quiet
The crash log has no stack trace, why?
2.4 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const loader = source`
  Future<void> upload(Report report) async {
    try {
      await uploadReport(report);
    } catch (e) {
      log('upload failed: $e');
    }
  }
`;

test("fires on a catch without a stack trace the agent writes", () => {
  expect(detect(write("lib/uploader.dart", loader))).toEqual([{ line: 4 }]);
});

test("stays quiet on a catch that keeps its stack trace", () => {
  const code = source`
    try {
      await uploadReport(report);
    } catch (e, stackTrace) {
      log('upload failed', error: e, stackTrace: stackTrace);
    } on FormatException catch (e, stack) {
      rethrow;
    }
  `;
  expect(detect(write("lib/uploader.dart", code))).toEqual([]);
});

test("stays quiet on catch (e) in a comment", () => {
  const code = source`
    /// Never write catch (e) here.
  `;
  expect(detect(write("lib/hint.dart", code))).toEqual([]);
});

test("stays quiet on a legacy catch when the agent edits elsewhere or reads", () => {
  expect(detect(edit("lib/uploader.dart", loader, { written: "    await uploadReport(report);" }))).toEqual([]);
  expect(detect(read("lib/uploader.dart", loader))).toEqual([]);
});

test("stays quiet in generated code", () => {
  expect(detect(write("lib/uploader.g.dart", loader))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions a stack trace", () => {
  expect(detect(prompt("The crash log has no stack trace, why?"), dartApp)).toEqual([{ match: "stack trace", depth: "pointer" }]);
});

test("stays quiet on the same words outside a Dart project", () => {
  expect(detect(prompt("The crash log has no stack trace, why?"))).toEqual([]);
});