Skip to content

Commit 9a429aa

Browse files
committed
feat: Remove badly designed error handling code
1 parent 0f54caf commit 9a429aa

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

packages/test-case-component/src/generateHtml.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { BundledLanguage } from "shiki";
33
import type { StepNameType, DataFixture } from "./types";
44
import type { ExtendedTestCaseSnapshot } from "./types";
55

6-
import { renderClipboard, renderError } from "./renderHtml";
6+
import { renderClipboard } from "./renderHtml";
77
import { getDecorations } from "./helpers/decorations";
88

99
/**
@@ -44,38 +44,23 @@ function createHtmlGenerator(data: DataFixture) {
4444
console.error(`Error in ${stepName} ${raw.command.spokenForm}`);
4545
return "Error";
4646
}
47-
const decorations = await getDecorations({ snapshot: state, command });
47+
const extendedState = { ...state, stepName };
48+
const decorations = await getDecorations({ snapshot: extendedState, command });
4849
const { documentContents } = state;
4950
const htmlArray: string[] = [];
5051
let codeBody;
51-
const errorLevels = [
52-
"excludes thatMarks sourceMarks selectionRanges ideFlashes",
53-
"excludes thatMarks sourceMarks selectionRanges",
54-
"excludes thatMarks sourceMarks",
55-
"excludes thatMarks",
56-
"success",
57-
];
58-
let errorLevel = errorLevels.length - 1;
59-
for (let i = decorations.length - 1; i >= 0; i--) {
60-
const fallbackDecoration = decorations.slice(0, i).flat();
61-
errorLevel = i;
62-
try {
63-
const marker = await createHighlighter();
64-
const options = {
65-
theme: "css-variables",
66-
lang,
67-
decorations: fallbackDecoration
68-
};
69-
codeBody = marker.codeToHtml(documentContents, options);
70-
htmlArray.push(codeBody);
71-
break;
72-
} catch (error) {
73-
console.warn(`"Failed with decorations level ${i}:"`, command);
74-
console.warn(fallbackDecoration, error);
75-
}
76-
}
77-
if (!codeBody) {
78-
console.error("All fallback levels failed. Unable to generate code body.");
52+
// Simplified: just try rendering once with all decorations
53+
try {
54+
const marker = await createHighlighter();
55+
const options = {
56+
theme: "css-variables",
57+
lang,
58+
decorations,
59+
};
60+
codeBody = marker.codeToHtml(documentContents, options);
61+
htmlArray.push(codeBody);
62+
} catch (error) {
63+
console.error("Failed to generate code body:", error);
7964
codeBody = "";
8065
}
8166

@@ -84,11 +69,6 @@ function createHtmlGenerator(data: DataFixture) {
8469
htmlArray.push(clipboardRendered);
8570
}
8671

87-
const errorRendered = renderError(errorLevel, errorLevels);
88-
if (errorRendered !== "") {
89-
htmlArray.push(errorRendered);
90-
}
91-
9272
return { html: htmlArray.join(""), data: [decorations] };
9373
}
9474

packages/test-case-component/src/helpers/decorations/createDecorations.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { getIdeFlashDecorations } from "./getIdeFlashDecorations";
1212
import { getSelections } from "./getSelections";
1313
import { getSourceMarks } from "./getSourceMarks";
1414
import { getThatMarks } from "./getThatMarks";
15+
1516
import type { StepNameType } from "../../types";
17+
import { mergeOverlappingDecorations } from "./mergeOverlappingDecorations";
1618

1719
export function createDecorations(
1820
options: {
@@ -29,8 +31,8 @@ export function createDecorations(
2931
thatMark?: TargetPlainObject[]
3032
}
3133
} = {}
32-
): DecorationItem[][] {
33-
const { marks, ide, lines, selections, thatMark, sourceMark, stepName } = options
34+
): DecorationItem[] {
35+
const { marks, ide, lines, selections, thatMark, sourceMark } = options
3436

3537
const decorations: DecorationItem[][] = [];
3638

@@ -50,7 +52,7 @@ export function createDecorations(
5052
} else {
5153
decorations.push([])
5254
}
53-
54-
return decorations
55+
const merged = mergeOverlappingDecorations(decorations.flat());
56+
return merged;
5557
}
5658

packages/test-case-component/src/helpers/decorations/getDecorations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export async function getDecorations({
1616
}: {
1717
snapshot: ExtendedTestCaseSnapshot;
1818
command: Command;
19-
}): Promise<DecorationItem[][]> {
20-
const { messages, flashes, highlights, finalStateMarkHelpers } = snapshot;
19+
}): Promise<DecorationItem[]> {
20+
const { messages, flashes, highlights } = snapshot;
2121
const potentialMarks = snapshot.marks || {};
2222
const lines = snapshot.documentContents.split("\n");
2323
// Use StepNameType for stepName, and provide a fallback if undefined

0 commit comments

Comments
 (0)