Skip to content

Commit 2f70be7

Browse files
authored
Highlight error message at the end of log (#71)
1 parent 2ed1cd8 commit 2f70be7

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/App.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,30 @@ describe("App", () => {
222222
expect(el.classList).toContain("selected-line");
223223
});
224224
});
225+
226+
it("labels the final error message", async () => {
227+
render(<App />);
228+
229+
const inputEl = document.getElementById("input-text");
230+
if (!inputEl) {
231+
throw new Error(DOM_EL_FAIL);
232+
}
233+
234+
fireEvent(
235+
inputEl,
236+
createEvent.paste(inputEl, {
237+
clipboardData: {
238+
getData: () => SAMPLE_LOG_DATA_2,
239+
},
240+
}),
241+
);
242+
243+
const line117El = document.getElementById("line-117");
244+
if (!line117El) {
245+
throw new Error(DOM_EL_FAIL);
246+
}
247+
248+
expect(line117El.classList).toContain("error-message");
249+
expect(line117El.innerHTML).toBe("R6 invalid mem access 'scalar'");
250+
});
225251
});

src/analyzer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export type VerifierLogState = {
7777
cLineIdtoIdx: Map<string, number>;
7878
bpfStates: BpfState[];
7979
cSourceMap: CSourceMap;
80+
lastInsIdx: number;
8081
};
8182

8283
export function makeValue(
@@ -272,6 +273,7 @@ export function getEmptyVerifierState(): VerifierLogState {
272273
cLineIdtoIdx: new Map(),
273274
bpfStates: [],
274275
cSourceMap: new CSourceMap(),
276+
lastInsIdx: 0,
275277
};
276278
}
277279

@@ -299,6 +301,7 @@ export function processRawLines(rawLines: string[]): VerifierLogState {
299301
let currentCSourceLine: CSourceLine | undefined;
300302
const cSourceMap = new CSourceMap();
301303
const knownMessageIdxs: number[] = [];
304+
let lastInsIdx: number = 0;
302305

303306
// First pass: parse individual lines
304307
lines = rawLines.map((rawLine, idx) => {
@@ -309,6 +312,13 @@ export function processRawLines(rawLines: string[]): VerifierLogState {
309312
return parsedLine;
310313
});
311314

315+
for (let i = lines.length - 1; i >= 0; --i) {
316+
if (lines[i].type == ParsedLineType.INSTRUCTION) {
317+
lastInsIdx = lines[i].idx;
318+
break;
319+
}
320+
}
321+
312322
// Process known messages and fixup parsed lines
313323
knownMessageIdxs.forEach((idx) => {
314324
const parsedLine = lines[idx];
@@ -378,6 +388,7 @@ export function processRawLines(rawLines: string[]): VerifierLogState {
378388
cSourceMap,
379389
cLines,
380390
cLineIdtoIdx,
391+
lastInsIdx,
381392
};
382393
}
383394

src/components.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ const LogLineRaw = ({
293293
state,
294294
indentLevel,
295295
idx,
296+
lastInsIdx,
296297
}: {
297298
line: ParsedLine;
298299
state: BpfState;
299300
indentLevel: number;
300301
idx: number;
302+
lastInsIdx: number;
301303
}) => {
302304
let content;
303305
const topClasses = ["log-line"];
@@ -312,7 +314,11 @@ const LogLineRaw = ({
312314
content = <>{line.raw}</>;
313315
break;
314316
default:
315-
topClasses.push("ignorable-line");
317+
if (lastInsIdx + 1 === idx) {
318+
topClasses.push("error-message");
319+
} else {
320+
topClasses.push("ignorable-line");
321+
}
316322
content = <>{line.raw}</>;
317323
break;
318324
}
@@ -703,7 +709,7 @@ const LogLinesRaw = ({
703709
handleLogLinesOver: (event: React.MouseEvent<HTMLDivElement>) => void;
704710
handleLogLinesOut: (event: React.MouseEvent<HTMLDivElement>) => void;
705711
}) => {
706-
const { bpfStates } = verifierLogState;
712+
const { bpfStates, lastInsIdx } = verifierLogState;
707713
let indentLevel = 0;
708714
return (
709715
<div
@@ -730,6 +736,7 @@ const LogLinesRaw = ({
730736
line={line}
731737
idx={line.idx}
732738
key={`log_line_${line.idx}`}
739+
lastInsIdx={lastInsIdx}
733740
/>
734741
);
735742
})}

src/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ h1 {
186186
color: #cccccc;
187187
}
188188

189+
.error-message {
190+
color: red;
191+
font-weight: bold;
192+
}
193+
189194
.inline-c-source-line,
190195
.active_mem_slot .inline-c-source-line.selected-line,
191196
.active_mem_slot .inline-c-source-line.dependency-line {

0 commit comments

Comments
 (0)