mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
- Entire stdout+stderr was passed to both title and body for the github issue, resulting in a failure due to github's validation Fixes: - Pass only the line containing "simulation failed:" as title - Pass max 50 lines following title as body - Truncate title and body to 255 and 65536 chars respectively before posting github issue, just to be sure
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
// Helper functions
|
|
|
|
export type StackTraceInfo = {
|
|
type: "panic";
|
|
trace: string;
|
|
mainError: string;
|
|
}
|
|
|
|
export type AssertionFailureInfo = {
|
|
type: "assertion";
|
|
output: string;
|
|
mainError: string;
|
|
}
|
|
|
|
/**
|
|
* Extract failure information from log output
|
|
*/
|
|
export function extractFailureInfo(output: string): StackTraceInfo | AssertionFailureInfo {
|
|
const lines = output.split('\n');
|
|
|
|
const info = getTraceFromOutput(lines) ?? getAssertionFailureInfo(lines);
|
|
|
|
if (!info) {
|
|
throw new Error("No failure information found");
|
|
}
|
|
|
|
return info;
|
|
}
|
|
|
|
function getTraceFromOutput(lines: string[]): StackTraceInfo | null {
|
|
const panicLineIndex = lines.findIndex(line => line.includes("panic occurred"));
|
|
if (panicLineIndex === -1) {
|
|
return null;
|
|
}
|
|
|
|
const startIndex = panicLineIndex + 1;
|
|
const endIndex = Math.min(lines.length, startIndex + 50);
|
|
|
|
const trace = lines.slice(startIndex, endIndex).join('\n');
|
|
const mainError = lines[startIndex] ?? "???";
|
|
|
|
return { type: "panic", trace, mainError };
|
|
}
|
|
|
|
function getAssertionFailureInfo(lines: string[]): AssertionFailureInfo | null {
|
|
const simulationFailedLineIndex = lines.findIndex(line => line.includes("simulation failed:"));
|
|
if (simulationFailedLineIndex === -1) {
|
|
return null;
|
|
}
|
|
|
|
const startIndex = simulationFailedLineIndex;
|
|
const endIndex = Math.min(lines.length, startIndex + 50);
|
|
|
|
const output = lines.slice(startIndex, endIndex).join('\n');
|
|
const mainError = lines[startIndex] ?? "???";
|
|
|
|
return { type: "assertion", output, mainError };
|
|
} |