paseo-plugin-genui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
// What `StackTrace` shows: an error as a runtime printed it (or as
|
|
2
|
+
// `{name, message, stack}`) read into the error that surfaced, its causes and
|
|
3
|
+
// an AggregateError's errors, each with its frames innermost first, for
|
|
4
|
+
// JavaScript (Node, V8, Firefox, Safari), Python, Java/Kotlin, Go, Rust, .NET,
|
|
5
|
+
// Ruby and Swift. Frame locations and the app/library split come from
|
|
6
|
+
// `stackFrame` in test-results.ts. Pure: no React, no DOM.
|
|
7
|
+
import { isPlainObject } from "./evaluate";
|
|
8
|
+
import { JVM_LIBRARY, stackFrame, stripAnsi, type StackFrame } from "./test-results";
|
|
9
|
+
import type { Value } from "./types";
|
|
10
|
+
|
|
11
|
+
export type TraceLanguage = "javascript" | "python" | "java" | "go" | "rust" | "dotnet" | "ruby" | "swift" | "text";
|
|
12
|
+
|
|
13
|
+
export interface TraceFrame {
|
|
14
|
+
/** The frame as printed, trimmed; a frame printed on two lines (Go, Rust) is both, joined by a space. */
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly fn: string | null;
|
|
17
|
+
readonly location: StackFrame | null;
|
|
18
|
+
/** The code being debugged, not a dependency, the runtime or the standard library. */
|
|
19
|
+
readonly app: boolean;
|
|
20
|
+
/** The source line Python prints under a frame. */
|
|
21
|
+
readonly source: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How a section relates to the section it belongs to: `cause` (Caused by,
|
|
26
|
+
* `[cause]`, Python's "direct cause", .NET's inner exception), `context`
|
|
27
|
+
* (Python: raised while this one was being handled), `member` (one of an
|
|
28
|
+
* AggregateError's errors), `suppressed` (Java).
|
|
29
|
+
*/
|
|
30
|
+
export type TraceRelation = "cause" | "context" | "member" | "suppressed";
|
|
31
|
+
|
|
32
|
+
export interface TraceSection {
|
|
33
|
+
/** `TypeError`, `java.lang.IllegalStateException`, `panic`; "" when the text names none. */
|
|
34
|
+
readonly type: string;
|
|
35
|
+
readonly message: string;
|
|
36
|
+
/** Innermost (where it was thrown) first. */
|
|
37
|
+
readonly frames: readonly TraceFrame[];
|
|
38
|
+
/** Frames the runtime left out as shared with another section (Java `... 6 more`, Node `... 2 lines matching cause stack trace ...`). */
|
|
39
|
+
readonly omitted: number;
|
|
40
|
+
/** Properties printed with the error (Node's `code: 'ECONNREFUSED'`). */
|
|
41
|
+
readonly fields: readonly (readonly [string, string])[];
|
|
42
|
+
/** Null for the error that surfaced, which comes first. */
|
|
43
|
+
readonly relation: TraceRelation | null;
|
|
44
|
+
/** 0 for the top error and its causes; one more inside each AggregateError or Java `Suppressed:` list. */
|
|
45
|
+
readonly depth: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Trace {
|
|
49
|
+
readonly language: TraceLanguage;
|
|
50
|
+
readonly sections: readonly TraceSection[];
|
|
51
|
+
/** Where it ran, as printed: `Node.js v22.1.0`, `thread 'main'`, `goroutine 1 [running]`, `exit status 2`. */
|
|
52
|
+
readonly notes: readonly string[];
|
|
53
|
+
/** The runtime printed the frames outermost first (Python), so they are shown reversed. */
|
|
54
|
+
readonly reversed: boolean;
|
|
55
|
+
/** The text read, ANSI codes stripped: what Copy copies. */
|
|
56
|
+
readonly raw: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type TraceResult = { readonly ok: true; readonly trace: Trace } | { readonly ok: false; readonly error: string };
|
|
60
|
+
|
|
61
|
+
const SHAPE_HINT = "StackTrace needs an error's text with its stack, or {name, message, stack}";
|
|
62
|
+
|
|
63
|
+
interface Section {
|
|
64
|
+
type: string;
|
|
65
|
+
message: string;
|
|
66
|
+
frames: TraceFrame[];
|
|
67
|
+
omitted: number;
|
|
68
|
+
fields: [string, string][];
|
|
69
|
+
relation: TraceRelation | null;
|
|
70
|
+
depth: number;
|
|
71
|
+
/** Indentation of the header line (JavaScript nesting). */
|
|
72
|
+
indent: number;
|
|
73
|
+
/** A `{` after the header or last frame opened a block of printed properties. */
|
|
74
|
+
braces: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface Parsed {
|
|
78
|
+
language: TraceLanguage;
|
|
79
|
+
sections: Section[];
|
|
80
|
+
notes: string[];
|
|
81
|
+
reversed: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function section(header: string, relation: TraceRelation | null, depth: number, indent = 0): Section {
|
|
85
|
+
const { type, message } = splitHeader(header);
|
|
86
|
+
return { type, message, frames: [], omitted: 0, fields: [], relation, depth, indent, braces: false };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `Type: message` → its parts; text that names no type is all message. */
|
|
90
|
+
export function splitHeader(text: string): { readonly type: string; readonly message: string } {
|
|
91
|
+
const trimmed = text.trim();
|
|
92
|
+
const match = /^((?:[A-Za-z_$][\w$]*[.:/]{1,2})*[A-Za-z_$][\w$]*(?: ?\[[\w-]+\])?)(?::(?:\s+|$)([\s\S]*))?$/.exec(trimmed);
|
|
93
|
+
if (match !== null && (match[2] !== undefined || /(?:Error|Exception|Throwable|Panic|Warning|Interrupt|Exit)$/.test(match[1]))) {
|
|
94
|
+
return { type: match[1], message: (match[2] ?? "").trim() };
|
|
95
|
+
}
|
|
96
|
+
return { type: "", message: trimmed };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function appendMessage(target: Section, line: string): void {
|
|
100
|
+
target.message = target.message === "" ? line : `${target.message}\n${line}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function frame(text: string, fn: string | null, location: StackFrame | null, app: boolean, source: string | null = null): TraceFrame {
|
|
104
|
+
return { text: text.trim(), fn: fn === null || fn.trim() === "" ? null : fn.trim(), location, app, source };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// Input
|
|
109
|
+
|
|
110
|
+
/** The error `value` describes, read; an error for anything that is no trace. */
|
|
111
|
+
export function readTrace(value: Value | undefined): TraceResult {
|
|
112
|
+
if (value !== undefined && value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
113
|
+
if (!isPlainObject(value as Value)) return { ok: false, error: SHAPE_HINT };
|
|
114
|
+
const parsed = fromObject(value as Readonly<Record<string, Value>>, null, 0, 0);
|
|
115
|
+
if (parsed === null) return { ok: false, error: SHAPE_HINT };
|
|
116
|
+
return { ok: true, trace: finish(parsed.parsed, parsed.raw) };
|
|
117
|
+
}
|
|
118
|
+
const text = Array.isArray(value)
|
|
119
|
+
? value.every((line) => typeof line === "string")
|
|
120
|
+
? value.join("\n")
|
|
121
|
+
: null
|
|
122
|
+
: typeof value === "string"
|
|
123
|
+
? value
|
|
124
|
+
: null;
|
|
125
|
+
if (text === null) return { ok: false, error: SHAPE_HINT };
|
|
126
|
+
const raw = clean(text);
|
|
127
|
+
if (raw === "") return { ok: false, error: "The trace is empty" };
|
|
128
|
+
return { ok: true, trace: finish(parse(raw), raw) };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function clean(text: string): string {
|
|
132
|
+
return stripAnsi(text)
|
|
133
|
+
.replace(/\r\n?/g, "\n")
|
|
134
|
+
.replace(/^(?:[ \t]*\n)+/, "")
|
|
135
|
+
.trimEnd();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function finish(parsed: Parsed, raw: string): Trace {
|
|
139
|
+
const sections = parsed.sections
|
|
140
|
+
.filter((s, index) => index === 0 || s.type !== "" || s.message !== "" || s.frames.length > 0)
|
|
141
|
+
.map(({ type, message, frames, omitted, fields, relation, depth }) => ({ type, message, frames, omitted, fields, relation, depth }));
|
|
142
|
+
return { language: parsed.language, sections, notes: parsed.notes, reversed: parsed.reversed, raw };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function field(record: Readonly<Record<string, Value>>, keys: readonly string[]): Value | undefined {
|
|
146
|
+
for (const key of keys) if (Object.hasOwn(record, key) && record[key] !== null) return record[key];
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function fieldText(value: Value | undefined): string | null {
|
|
151
|
+
if (typeof value === "string") return value;
|
|
152
|
+
if (Array.isArray(value) && value.every((line) => typeof line === "string")) return value.join("\n");
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* `{name, message, stack, cause?, errors?}` (a serialized Error, pino's
|
|
158
|
+
* `err`, a browser's error event). A stack that does not repeat the header
|
|
159
|
+
* (Firefox, Safari) gets it put in front.
|
|
160
|
+
*/
|
|
161
|
+
function fromObject(
|
|
162
|
+
record: Readonly<Record<string, Value>>,
|
|
163
|
+
relation: TraceRelation | null,
|
|
164
|
+
depth: number,
|
|
165
|
+
level: number,
|
|
166
|
+
): { parsed: Parsed; raw: string } | null {
|
|
167
|
+
const name = fieldText(field(record, ["name", "type", "errorType", "class"]))?.trim() ?? "";
|
|
168
|
+
const message = fieldText(field(record, ["message", "msg", "reason", "value"])) ?? "";
|
|
169
|
+
const stack = fieldText(field(record, ["stack", "stacktrace", "traceback", "backtrace"]));
|
|
170
|
+
if (name === "" && message === "" && stack === null) return null;
|
|
171
|
+
const header = name === "" ? message : message === "" ? name : `${name}: ${message}`;
|
|
172
|
+
let text = clean(stack ?? header);
|
|
173
|
+
if (stack !== null) {
|
|
174
|
+
const first = text.split("\n", 1)[0].trim();
|
|
175
|
+
const framesOnly = first === "" || stackFrame(first) !== null || /^at\s|@/.test(first) || /^\s/.test(text);
|
|
176
|
+
if (framesOnly && header !== "" && !(message !== "" && first.includes(message.split("\n", 1)[0]))) text = `${header}\n${text}`;
|
|
177
|
+
}
|
|
178
|
+
const parsed = parse(text);
|
|
179
|
+
const sections = parsed.sections;
|
|
180
|
+
if (sections.length > 0) {
|
|
181
|
+
sections[0].relation = relation;
|
|
182
|
+
for (const each of sections) each.depth += depth;
|
|
183
|
+
}
|
|
184
|
+
let raw = text;
|
|
185
|
+
if (level < 8) {
|
|
186
|
+
const cause = field(record, ["cause"]);
|
|
187
|
+
if (cause !== undefined && isPlainObject(cause)) {
|
|
188
|
+
const read = fromObject(cause, "cause", depth, level + 1);
|
|
189
|
+
if (read !== null) {
|
|
190
|
+
sections.push(...read.parsed.sections);
|
|
191
|
+
raw += `\nCaused by: ${read.raw}`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const errors = field(record, ["errors"]);
|
|
195
|
+
if (Array.isArray(errors)) {
|
|
196
|
+
for (const item of errors.slice(0, 50)) {
|
|
197
|
+
if (!isPlainObject(item)) continue;
|
|
198
|
+
const read = fromObject(item, "member", depth + 1, level + 1);
|
|
199
|
+
if (read !== null) {
|
|
200
|
+
sections.push(...read.parsed.sections);
|
|
201
|
+
raw += `\n ${read.raw.split("\n").join("\n ")}`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return { parsed, raw };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
// Dispatch
|
|
211
|
+
|
|
212
|
+
const PYTHON = /^\s*Traceback \(most recent call last\):\s*$/m;
|
|
213
|
+
const GO = /^(?:panic|fatal error): /m;
|
|
214
|
+
const RUST = /^thread '[^']*'(?: \(\d+\))? panicked at /m;
|
|
215
|
+
const DOTNET = /^\s*at \S.*\) in \S.*:line \d+\s*$|^\s*---> \S|^Unhandled exception\. /m;
|
|
216
|
+
const JAVA = /^\s*at [\w$.<>/-]+\((?:[\w$.-]+\.(?:java|kt|kts|scala|groovy|clj)(?::\d+)?|Native Method|Unknown Source)\)\s*$/m;
|
|
217
|
+
const RUBY = /^\S+?:\d+:in [`'].*?': [\s\S]*?\([\w:]+\)\s*$|^\s+from \S+?:\d+:in [`']/m;
|
|
218
|
+
const SWIFT = /^\S+?\.swift:\d+: Fatal error: /m;
|
|
219
|
+
|
|
220
|
+
function parse(text: string): Parsed {
|
|
221
|
+
if (PYTHON.test(text)) return parsePython(text);
|
|
222
|
+
if (GO.test(text) && /\.go:\d+/.test(text)) return parseGo(text);
|
|
223
|
+
if (RUST.test(text)) return parseRust(text);
|
|
224
|
+
if (DOTNET.test(text)) return parseDotnet(text);
|
|
225
|
+
if (JAVA.test(text)) return parseJava(text);
|
|
226
|
+
if (RUBY.test(text)) return parseRuby(text);
|
|
227
|
+
if (SWIFT.test(text)) return parseSwift(text);
|
|
228
|
+
return parseJavaScript(text);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
// JavaScript: V8 (Node, Chrome, Deno, Bun), Firefox, Safari, and any text
|
|
233
|
+
|
|
234
|
+
const V8_FRAME = /^at\s+(?:(.+?)\s+\((.*)\)|(.+))$/;
|
|
235
|
+
const AT_SIGN_FRAME = /^([^\s@]*)@(\S.*?)$/;
|
|
236
|
+
const RUNTIME_NOTE = /^(?:Node\.js|Deno|Bun) v\d[\w.-]*$/;
|
|
237
|
+
const OMITTED = /^\.\.\. (\d+) lines? matching cause stack trace \.\.\.$/;
|
|
238
|
+
const PROPERTY = /^((?:[\w$]+|'[^']*'|"[^"]*"|\[[\w$.]+\])):\s(.*?),?$/;
|
|
239
|
+
|
|
240
|
+
function parseJavaScript(text: string): Parsed {
|
|
241
|
+
const lines = text.split("\n");
|
|
242
|
+
const sections: Section[] = [];
|
|
243
|
+
const notes: string[] = [];
|
|
244
|
+
/** Open `[errors]: [` lists: their indentation, their members' (once seen) and the depth of the AggregateError holding them. */
|
|
245
|
+
const lists: { indent: number; members: number | null; depth: number }[] = [];
|
|
246
|
+
let browser = false;
|
|
247
|
+
let start = 0;
|
|
248
|
+
// Node's uncaught-exception preamble: `file:line`, the source line, a caret, a blank line.
|
|
249
|
+
if (/^(?:file:\/\/)?\S+:\d+$/.test(lines[0].trim()) && lines.slice(1, 4).some((line) => /^\s*\^+\s*$/.test(line))) {
|
|
250
|
+
const blank = lines.findIndex((line, index) => index > 0 && line.trim() === "");
|
|
251
|
+
start = blank === -1 ? 1 : blank + 1;
|
|
252
|
+
}
|
|
253
|
+
const current = (): Section | undefined => sections[sections.length - 1];
|
|
254
|
+
const open = (header: string, relation: TraceRelation | null, indent: number): Section => {
|
|
255
|
+
let depth = 0;
|
|
256
|
+
if (relation === "member") depth = (lists[lists.length - 1]?.depth ?? 0) + 1;
|
|
257
|
+
else if (relation !== null) {
|
|
258
|
+
const before = [...sections].reverse();
|
|
259
|
+
const owner = before.find((s) => s.indent < indent) ?? before.find((s) => s.indent <= indent);
|
|
260
|
+
depth = owner?.depth ?? 0;
|
|
261
|
+
}
|
|
262
|
+
let body = header.trim();
|
|
263
|
+
let braces = false;
|
|
264
|
+
if (body.endsWith(" {")) {
|
|
265
|
+
body = body.slice(0, -2).trimEnd();
|
|
266
|
+
braces = true;
|
|
267
|
+
}
|
|
268
|
+
// Node prints errors without a stack as `[TypeError: fetch failed]`.
|
|
269
|
+
const bracketed = /^\[(.*)\]$/.exec(body);
|
|
270
|
+
if (bracketed !== null) body = bracketed[1];
|
|
271
|
+
const made = section(body.replace(/^Uncaught (?:\(in promise\) )?/, ""), relation, depth, indent);
|
|
272
|
+
made.braces = braces;
|
|
273
|
+
sections.push(made);
|
|
274
|
+
return made;
|
|
275
|
+
};
|
|
276
|
+
for (let index = start; index < lines.length; index++) {
|
|
277
|
+
const line = lines[index];
|
|
278
|
+
const trimmed = line.trim();
|
|
279
|
+
const indent = line.length - line.trimStart().length;
|
|
280
|
+
if (trimmed === "") continue;
|
|
281
|
+
if (RUNTIME_NOTE.test(trimmed)) {
|
|
282
|
+
notes.push(trimmed);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const omitted = OMITTED.exec(trimmed);
|
|
286
|
+
if (omitted !== null) {
|
|
287
|
+
if (current() !== undefined) current()!.omitted += Number(omitted[1]);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
let body = trimmed;
|
|
291
|
+
let braces = false;
|
|
292
|
+
if (/^at\s/.test(body)) {
|
|
293
|
+
// Inside Node's printed objects a frame line may end the error (`,`) or open its properties (` {`).
|
|
294
|
+
body = body.replace(/,$/, "");
|
|
295
|
+
if (body.endsWith(" {")) {
|
|
296
|
+
body = body.slice(0, -2);
|
|
297
|
+
braces = true;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const v8 = V8_FRAME.exec(body);
|
|
301
|
+
const atSign = v8 === null && (!body.includes(" ") || body.endsWith("@[native code]")) ? AT_SIGN_FRAME.exec(body) : null;
|
|
302
|
+
if (v8 !== null || (atSign !== null && (stackFrame(body) !== null || /@\[native code\]$|@(?:https?|file|webpack[\w-]*|blob|chrome-extension|moz-extension):/.test(body)))) {
|
|
303
|
+
if (atSign !== null) browser = true;
|
|
304
|
+
const target = current() ?? open("", null, indent);
|
|
305
|
+
const location = stackFrame(body);
|
|
306
|
+
const fn = v8 !== null ? (v8[1] ?? null) : atSign![1];
|
|
307
|
+
target.frames.push(frame(body, fn, location, location?.app ?? false));
|
|
308
|
+
if (braces) target.braces = true;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (/^\[errors\]: \[$/.test(trimmed)) {
|
|
312
|
+
lists.push({ indent, members: null, depth: current()?.depth ?? 0 });
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (/^[\]}],?$/.test(trimmed)) {
|
|
316
|
+
if (trimmed.startsWith("]") && lists.length > 0) lists.pop();
|
|
317
|
+
else if (current() !== undefined) current()!.braces = false;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const cause = /^(?:\[cause\]:|Caused by:)\s*(.*)$/.exec(trimmed);
|
|
321
|
+
if (cause !== null) {
|
|
322
|
+
open(cause[1], "cause", indent);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
// Each of an AggregateError's errors starts at the indentation of the first one.
|
|
326
|
+
const list = lists[lists.length - 1];
|
|
327
|
+
if (list !== undefined && (list.members === null ? indent > list.indent : indent === list.members)) {
|
|
328
|
+
list.members = indent;
|
|
329
|
+
open(trimmed.replace(/,$/, ""), "member", indent);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const target = current();
|
|
333
|
+
if (target === undefined) {
|
|
334
|
+
open(trimmed, null, indent);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (target.braces) {
|
|
338
|
+
const property = PROPERTY.exec(trimmed);
|
|
339
|
+
if (property !== null) {
|
|
340
|
+
target.fields.push([property[1].replace(/^['"[]|['"\]]$/g, ""), property[2].replace(/^'(.*)'$/, "$1")]);
|
|
341
|
+
if (property[2].endsWith("{") || property[2].endsWith("[")) target.braces = true;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (target.frames.length === 0) {
|
|
346
|
+
appendMessage(target, trimmed);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
// A frame some other way (`src/a.ts:12:5`, a pytest location): kept; anything else after the frames is left out.
|
|
350
|
+
const location = stackFrame(line);
|
|
351
|
+
if (location !== null) target.frames.push(frame(trimmed, null, location, location.app));
|
|
352
|
+
}
|
|
353
|
+
const hasV8 = sections.some((s) => s.frames.some((f) => f.text.startsWith("at ")));
|
|
354
|
+
return { language: browser || hasV8 ? "javascript" : "text", sections: sections.length > 0 ? sections : [section(text, null, 0)], notes, reversed: false };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
// Python: chained tracebacks, frames printed outermost first
|
|
359
|
+
|
|
360
|
+
const PYTHON_FRAME = /^(\s*)File "([^"]+)", line (\d+)(?:, in (.+))?$/;
|
|
361
|
+
const PYTHON_CHAIN: Readonly<Record<string, TraceRelation>> = {
|
|
362
|
+
"The above exception was the direct cause of the following exception:": "cause",
|
|
363
|
+
"During handling of the above exception, another exception occurred:": "context",
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
function parsePython(text: string): Parsed {
|
|
367
|
+
const chunks: { lines: string[]; joined: TraceRelation | null }[] = [{ lines: [], joined: null }];
|
|
368
|
+
for (const line of text.split("\n")) {
|
|
369
|
+
const relation = PYTHON_CHAIN[line.trim()];
|
|
370
|
+
if (relation !== undefined) chunks.push({ lines: [], joined: relation });
|
|
371
|
+
else chunks[chunks.length - 1].lines.push(line);
|
|
372
|
+
}
|
|
373
|
+
const read = chunks.map((chunk) => {
|
|
374
|
+
const lines = chunk.lines;
|
|
375
|
+
const begin = lines.findIndex((line) => PYTHON.test(line));
|
|
376
|
+
const frames: TraceFrame[] = [];
|
|
377
|
+
let exception: string[] = [];
|
|
378
|
+
for (let index = begin + 1; index < lines.length; index++) {
|
|
379
|
+
const line = lines[index];
|
|
380
|
+
const match = PYTHON_FRAME.exec(line);
|
|
381
|
+
if (match !== null) {
|
|
382
|
+
const depth = match[1].length;
|
|
383
|
+
let source: string | null = null;
|
|
384
|
+
while (index + 1 < lines.length) {
|
|
385
|
+
const next = lines[index + 1];
|
|
386
|
+
if (next.trim() !== "" && next.length - next.trimStart().length <= depth) break;
|
|
387
|
+
index++;
|
|
388
|
+
if (source === null && next.trim() !== "" && !/^\s*[~^]+\s*$/.test(next)) source = next.trim();
|
|
389
|
+
}
|
|
390
|
+
const location = stackFrame(line);
|
|
391
|
+
frames.push(frame(line, match[4] ?? null, location, location?.app ?? false, source));
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (line.trim() !== "") {
|
|
395
|
+
exception = lines.slice(index).filter((rest, at, all) => rest.trim() !== "" || at < all.length - 1);
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const header = exception.join("\n").trim();
|
|
400
|
+
const made = section(header, null, 0);
|
|
401
|
+
if (begin === -1) made.message = lines.join("\n").trim();
|
|
402
|
+
made.frames = frames.reverse();
|
|
403
|
+
return { made, joined: chunk.joined };
|
|
404
|
+
});
|
|
405
|
+
// The exception that surfaced is printed last; each earlier one is joined to the next by the line between them.
|
|
406
|
+
const sections: Section[] = [];
|
|
407
|
+
for (let index = read.length - 1; index >= 0; index--) {
|
|
408
|
+
const made = read[index].made;
|
|
409
|
+
made.relation = index === read.length - 1 ? null : read[index + 1].joined;
|
|
410
|
+
sections.push(made);
|
|
411
|
+
}
|
|
412
|
+
return { language: "python", sections, notes: [], reversed: true };
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ---------------------------------------------------------------------------
|
|
416
|
+
// Go: a panic and its goroutines
|
|
417
|
+
|
|
418
|
+
function parseGo(text: string): Parsed {
|
|
419
|
+
const lines = text.split("\n");
|
|
420
|
+
const notes: string[] = [];
|
|
421
|
+
const head = lines.findIndex((line) => GO.test(line));
|
|
422
|
+
const match = /^(panic|fatal error): ([\s\S]*)$/.exec(lines[head]);
|
|
423
|
+
const made = section("", null, 0);
|
|
424
|
+
made.type = match?.[1] ?? "panic";
|
|
425
|
+
made.message = (match?.[2] ?? "").replace(/ \[recovered\]$/, "");
|
|
426
|
+
let index = head + 1;
|
|
427
|
+
for (; index < lines.length && !/^goroutine \d+ \[/.test(lines[index]); index++) {
|
|
428
|
+
const trimmed = lines[index].trim();
|
|
429
|
+
if (trimmed === "") continue;
|
|
430
|
+
if (/^\[signal /.test(trimmed)) notes.push(trimmed);
|
|
431
|
+
else appendMessage(made, trimmed);
|
|
432
|
+
}
|
|
433
|
+
let goroutines = 0;
|
|
434
|
+
for (; index < lines.length; index++) {
|
|
435
|
+
const line = lines[index];
|
|
436
|
+
if (/^goroutine \d+ \[/.test(line)) {
|
|
437
|
+
goroutines++;
|
|
438
|
+
if (goroutines === 1) notes.push(line.replace(/:$/, ""));
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (/^exit status \d+$/.test(line.trim())) {
|
|
442
|
+
notes.push(line.trim());
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (goroutines !== 1 || line.trim() === "" || /^\s/.test(line)) continue;
|
|
446
|
+
const next = lines[index + 1] ?? "";
|
|
447
|
+
const location = /^\s+\S+:\d+/.test(next) ? stackFrame(next) : null;
|
|
448
|
+
if (location !== null) index++;
|
|
449
|
+
const fn = line.replace(/\((?:[^()]|\([^()]*\))*\)$/, "").replace(/ in goroutine \d+$/, "");
|
|
450
|
+
const library = location === null || !location.app || /^runtime\./.test(fn);
|
|
451
|
+
made.frames.push(frame(location === null ? line : `${line.trim()} ${next.trim()}`, fn, location, !library));
|
|
452
|
+
}
|
|
453
|
+
if (goroutines > 1) notes.push(`${goroutines - 1} other ${goroutines === 2 ? "goroutine" : "goroutines"}`);
|
|
454
|
+
return { language: "go", sections: [made], notes, reversed: false };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// ---------------------------------------------------------------------------
|
|
458
|
+
// Rust: a panic, its message, and the backtrace when RUST_BACKTRACE is set
|
|
459
|
+
|
|
460
|
+
const RUST_HEAD = /^thread '([^']*)'(?: \(\d+\))? panicked at (?:'([\s\S]*?)', )?(\S+?:\d+:\d+):?\s*$/;
|
|
461
|
+
const RUST_RUNTIME = /^(?:<?(?:std|core|alloc|test|tokio|futures)::|<[^>]*\b(?:std|core|alloc)::|__rustc::|rust_begin_unwind|__rust_|_?start$|__libc_start|start_thread|_?main$|<unknown>$)/;
|
|
462
|
+
|
|
463
|
+
function parseRust(text: string): Parsed {
|
|
464
|
+
const lines = text.split("\n");
|
|
465
|
+
const notes: string[] = [];
|
|
466
|
+
const head = lines.findIndex((line) => RUST.test(line));
|
|
467
|
+
const match = RUST_HEAD.exec(lines[head]);
|
|
468
|
+
const made = section("", null, 0);
|
|
469
|
+
made.type = "panic";
|
|
470
|
+
if (match !== null) {
|
|
471
|
+
notes.push(`thread '${match[1]}'`);
|
|
472
|
+
if (match[2] !== undefined) made.message = match[2];
|
|
473
|
+
}
|
|
474
|
+
let index = head + 1;
|
|
475
|
+
for (; index < lines.length; index++) {
|
|
476
|
+
const trimmed = lines[index].trim();
|
|
477
|
+
if (trimmed === "stack backtrace:") break;
|
|
478
|
+
if (trimmed.startsWith("note: ")) notes.push(trimmed.slice(6));
|
|
479
|
+
else if (trimmed !== "" && match?.[2] === undefined) appendMessage(made, trimmed);
|
|
480
|
+
}
|
|
481
|
+
// After the frames, Rust only says the backtrace is abridged (`RUST_BACKTRACE=full` prints more): nothing to show.
|
|
482
|
+
for (index++; index < lines.length; index++) {
|
|
483
|
+
const numbered = /^\s*\d+:\s+(.+)$/.exec(lines[index]);
|
|
484
|
+
if (numbered === null) continue;
|
|
485
|
+
const next = lines[index + 1] ?? "";
|
|
486
|
+
const location = /^\s+at\s/.test(next) ? stackFrame(next) : null;
|
|
487
|
+
if (location !== null) index++;
|
|
488
|
+
const fn = numbered[1].trim();
|
|
489
|
+
const app = !RUST_RUNTIME.test(fn) && (location === null || location.app);
|
|
490
|
+
made.frames.push(frame(location === null ? fn : `${fn} ${next.trim()}`, fn, location, app));
|
|
491
|
+
}
|
|
492
|
+
if (made.frames.length === 0 && match !== null) {
|
|
493
|
+
const location = stackFrame(`panicked at ${match[3]}`);
|
|
494
|
+
made.frames.push(frame(match[3], null, location, location?.app ?? false));
|
|
495
|
+
}
|
|
496
|
+
return { language: "rust", sections: [made], notes, reversed: false };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
// .NET: inner exceptions printed inside the outer one
|
|
501
|
+
|
|
502
|
+
const DOTNET_FRAME = /^at\s+(.+?)(?:\s+in\s+(.+):line\s+(\d+))?$/;
|
|
503
|
+
const DOTNET_RUNTIME = /^(?:System|Microsoft|Xunit|NUnit|Internal)\./;
|
|
504
|
+
|
|
505
|
+
function parseDotnet(text: string): Parsed {
|
|
506
|
+
const sections: Section[] = [];
|
|
507
|
+
const open: Section[] = [];
|
|
508
|
+
for (const line of text.split("\n")) {
|
|
509
|
+
const trimmed = line.trim();
|
|
510
|
+
if (trimmed === "" || /^--- End of stack trace from previous location/.test(trimmed)) continue;
|
|
511
|
+
if (/^--- End of inner exception stack trace ---$/.test(trimmed)) {
|
|
512
|
+
if (open.length > 1) open.pop();
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const inner = /^---> (.*)$/.exec(trimmed);
|
|
516
|
+
if (inner !== null && open.length > 0) {
|
|
517
|
+
const made = section(inner[1], "cause", 0);
|
|
518
|
+
sections.push(made);
|
|
519
|
+
open.push(made);
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const match = DOTNET_FRAME.exec(trimmed);
|
|
523
|
+
const target = open[open.length - 1];
|
|
524
|
+
if (match !== null && target !== undefined) {
|
|
525
|
+
const location = match[2] === undefined ? null : stackFrame(line);
|
|
526
|
+
const app = !DOTNET_RUNTIME.test(match[1]) && (location === null || location.app);
|
|
527
|
+
target.frames.push(frame(trimmed, match[1], location, app));
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (target === undefined) {
|
|
531
|
+
const made = section(trimmed.replace(/^Unhandled exception\.\s*/, ""), null, 0);
|
|
532
|
+
sections.push(made);
|
|
533
|
+
open.push(made);
|
|
534
|
+
} else if (target.frames.length === 0) appendMessage(target, trimmed);
|
|
535
|
+
}
|
|
536
|
+
return { language: "dotnet", sections, notes: [], reversed: false };
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ---------------------------------------------------------------------------
|
|
540
|
+
// Java, Kotlin, Scala
|
|
541
|
+
|
|
542
|
+
const JVM_AT = /^at\s+([\w$.<>/-]+)\((.*)\)$/;
|
|
543
|
+
|
|
544
|
+
function parseJava(text: string): Parsed {
|
|
545
|
+
const sections: Section[] = [];
|
|
546
|
+
const notes: string[] = [];
|
|
547
|
+
for (const line of text.split("\n")) {
|
|
548
|
+
const trimmed = line.trim();
|
|
549
|
+
if (trimmed === "") continue;
|
|
550
|
+
const tabs = /^\t*/.exec(line)![0].length;
|
|
551
|
+
const target = sections[sections.length - 1];
|
|
552
|
+
const at = JVM_AT.exec(trimmed);
|
|
553
|
+
if (at !== null && target !== undefined) {
|
|
554
|
+
const location = stackFrame(line);
|
|
555
|
+
const app = location !== null ? location.app : !JVM_LIBRARY.test(at[1]) && at[2] !== "Native Method";
|
|
556
|
+
target.frames.push(frame(trimmed, at[1], location, app));
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const more = /^\.\.\. (\d+) (?:more|common frames omitted)$/.exec(trimmed);
|
|
560
|
+
if (more !== null) {
|
|
561
|
+
if (target !== undefined) target.omitted += Number(more[1]);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
const linked = /^(Caused by|Suppressed): (.*)$/.exec(trimmed);
|
|
565
|
+
if (linked !== null) {
|
|
566
|
+
sections.push(section(linked[2], linked[1] === "Caused by" ? "cause" : "suppressed", tabs));
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (target === undefined) {
|
|
570
|
+
const thread = /^Exception in thread "([^"]*)" (.*)$/.exec(trimmed);
|
|
571
|
+
if (thread !== null) notes.push(`thread "${thread[1]}"`);
|
|
572
|
+
else if (/^(?:FATAL EXCEPTION|Process): /.test(trimmed)) {
|
|
573
|
+
notes.push(trimmed);
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
sections.push(section(thread?.[2] ?? trimmed, null, 0));
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (target.frames.length === 0) appendMessage(target, trimmed);
|
|
580
|
+
}
|
|
581
|
+
return { language: "java", sections, notes, reversed: false };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// ---------------------------------------------------------------------------
|
|
585
|
+
// Ruby, Swift
|
|
586
|
+
|
|
587
|
+
const RUBY_FRAME = /^(?:from\s+)?(.+?):(\d+):in [`'](.*?)'(?::\s([\s\S]*))?$/;
|
|
588
|
+
|
|
589
|
+
function parseRuby(text: string): Parsed {
|
|
590
|
+
const lines = text.split("\n");
|
|
591
|
+
let made: Section | null = null;
|
|
592
|
+
for (const line of lines) {
|
|
593
|
+
const trimmed = line.trim();
|
|
594
|
+
if (trimmed === "") continue;
|
|
595
|
+
const match = RUBY_FRAME.exec(trimmed);
|
|
596
|
+
if (match === null) {
|
|
597
|
+
if (made === null) made = section(trimmed, null, 0);
|
|
598
|
+
else if (made.frames.length <= 1) appendMessage(made, trimmed);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
if (made === null) {
|
|
602
|
+
// `app.rb:3:in 'm': divided by 0 (ZeroDivisionError)`: the first frame carries the error.
|
|
603
|
+
const error = /^([\s\S]*?) \(([\w:]+)\)$/.exec(match[4] ?? "");
|
|
604
|
+
made = section("", null, 0);
|
|
605
|
+
made.type = error?.[2] ?? "";
|
|
606
|
+
made.message = error?.[1] ?? match[4] ?? "";
|
|
607
|
+
}
|
|
608
|
+
const location = stackFrame(`${match[1]}:${match[2]}:in`);
|
|
609
|
+
made.frames.push(frame(trimmed.replace(/:\s[\s\S]*$/, ""), match[3], location, location?.app ?? false));
|
|
610
|
+
}
|
|
611
|
+
return { language: "ruby", sections: made === null ? [] : [made], notes: [], reversed: false };
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function parseSwift(text: string): Parsed {
|
|
615
|
+
const sections: Section[] = [];
|
|
616
|
+
const notes: string[] = [];
|
|
617
|
+
for (const line of text.split("\n")) {
|
|
618
|
+
const match = /^(\S+?\.swift):(\d+): Fatal error: (.*)$/.exec(line.trim());
|
|
619
|
+
if (match === null) {
|
|
620
|
+
if (line.trim() !== "" && sections.length === 0) notes.push(line.trim());
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const made = section("", null, 0);
|
|
624
|
+
made.type = "Fatal error";
|
|
625
|
+
made.message = match[3];
|
|
626
|
+
const location = stackFrame(`${match[1]}:${match[2]}`);
|
|
627
|
+
made.frames.push(frame(`${match[1]}:${match[2]}`, null, location, location?.app ?? false));
|
|
628
|
+
sections.push(made);
|
|
629
|
+
}
|
|
630
|
+
return { language: "swift", sections, notes, reversed: false };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// ---------------------------------------------------------------------------
|
|
634
|
+
// Reading a section
|
|
635
|
+
|
|
636
|
+
/** Frames and runs of 2+ consecutive library frames folded into one row. */
|
|
637
|
+
export type FrameRow = { readonly type: "frame"; readonly index: number } | { readonly type: "fold"; readonly start: number; readonly count: number };
|
|
638
|
+
|
|
639
|
+
export function frameRows(frames: readonly TraceFrame[], unfolded: ReadonlySet<number>): FrameRow[] {
|
|
640
|
+
const rows: FrameRow[] = [];
|
|
641
|
+
for (let index = 0; index < frames.length; ) {
|
|
642
|
+
let end = index;
|
|
643
|
+
while (end < frames.length && !frames[end].app) end++;
|
|
644
|
+
if (end - index >= 2 && !unfolded.has(index)) {
|
|
645
|
+
rows.push({ type: "fold", start: index, count: end - index });
|
|
646
|
+
index = end;
|
|
647
|
+
} else {
|
|
648
|
+
const stop = Math.max(end, index + 1);
|
|
649
|
+
for (; index < stop; index++) rows.push({ type: "frame", index });
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return rows;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* The file that holds a frame's code: its own path, or for a JVM frame (which
|
|
657
|
+
* names only `Cls.java`) where Maven and Gradle keep its package's sources;
|
|
658
|
+
* null for frames without one.
|
|
659
|
+
*/
|
|
660
|
+
export function sourcePath(f: TraceFrame): string | null {
|
|
661
|
+
const location = f.location;
|
|
662
|
+
if (location === null) return null;
|
|
663
|
+
if (location.linkable) {
|
|
664
|
+
if (!location.path.startsWith("file://")) return location.path;
|
|
665
|
+
try {
|
|
666
|
+
return decodeURI(location.path.slice(7));
|
|
667
|
+
} catch {
|
|
668
|
+
return location.path.slice(7);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
const parts = (f.fn ?? "").replace(/^[\w.]+\//, "").split(".");
|
|
672
|
+
const cls = parts.findIndex((part) => /^[A-Z]/.test(part));
|
|
673
|
+
if (cls <= 0) return null;
|
|
674
|
+
return `src/main/${/\.kts?$/.test(location.path) ? "kotlin" : "java"}/${parts.slice(0, cls).join("/")}/${location.path}`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export const LANGUAGE_NAMES: Readonly<Record<TraceLanguage, string>> = {
|
|
678
|
+
javascript: "JavaScript",
|
|
679
|
+
python: "Python",
|
|
680
|
+
java: "JVM",
|
|
681
|
+
go: "Go",
|
|
682
|
+
rust: "Rust",
|
|
683
|
+
dotnet: ".NET",
|
|
684
|
+
ruby: "Ruby",
|
|
685
|
+
swift: "Swift",
|
|
686
|
+
text: "",
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
/** The line that introduces a section after the first: "Caused by", "While handling", "Error 2 of 3", "Suppressed". */
|
|
690
|
+
export function relationLabel(relation: TraceRelation | null, member: { readonly index: number; readonly count: number } | null): string {
|
|
691
|
+
switch (relation) {
|
|
692
|
+
case "cause":
|
|
693
|
+
return "Caused by";
|
|
694
|
+
case "context":
|
|
695
|
+
return "While handling";
|
|
696
|
+
case "suppressed":
|
|
697
|
+
return "Suppressed";
|
|
698
|
+
case "member":
|
|
699
|
+
return member === null ? "Error" : `Error ${member.index} of ${member.count}`;
|
|
700
|
+
default:
|
|
701
|
+
return "";
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** For each section, its place among its AggregateError's errors (null for others). */
|
|
706
|
+
export function memberPlaces(sections: readonly TraceSection[]): ({ readonly index: number; readonly count: number } | null)[] {
|
|
707
|
+
const places: ({ index: number; count: number } | null)[] = sections.map(() => null);
|
|
708
|
+
for (let index = 0; index < sections.length; index++) {
|
|
709
|
+
if (sections[index].relation !== "member" || places[index] !== null) continue;
|
|
710
|
+
const depth = sections[index].depth;
|
|
711
|
+
const group: number[] = [];
|
|
712
|
+
for (let at = index; at < sections.length && sections[at].depth >= depth; at++) {
|
|
713
|
+
if (sections[at].depth === depth && sections[at].relation === "member") group.push(at);
|
|
714
|
+
}
|
|
715
|
+
group.forEach((at, position) => (places[at] = { index: position + 1, count: group.length }));
|
|
716
|
+
}
|
|
717
|
+
return places;
|
|
718
|
+
}
|