mirror of
https://github.com/hi-language/transpiler.git
synced 2026-01-14 00:28:05 +00:00
Fix: Implement global try/catch to log all errors
This commit is contained in:
@@ -44,34 +44,31 @@ function generateMarkdownReport(results) {
|
||||
return report;
|
||||
}
|
||||
|
||||
function generateBuildFailureReport(error) {
|
||||
function generateCrashReport(error, step) {
|
||||
let report = `# Hi Language Test Results\n\n`;
|
||||
report += `**Run at:** ${new Date().toISOString()}\n\n`;
|
||||
report += `| Test Case | Status |\n`;
|
||||
report += `|-----------|--------|\n`;
|
||||
report += `| Build Step | ❌ FAIL |\n`;
|
||||
report += `| ${step} | ❌ FAIL |\n`;
|
||||
report += `\n---\n\n## Failures\n\n`;
|
||||
report += `### \`Build Step\`\n\n`;
|
||||
report += `**Reason:** Master, failed to build parser from \`grammar.ne\`.\n\n`;
|
||||
report += `**Error:**\n\`\`\`\n${error.stderr || error.message}\n\`\`\`\n\n`;
|
||||
report += `### \`${step}\`\n\n`;
|
||||
report += `**Reason:** Master, the test runner encountered a fatal error.\n\n`;
|
||||
report += `**Error:**\n\`\`\`\n${error.stack || error.message}\n\`\`\`\n\n`;
|
||||
report += `---\n\n`;
|
||||
return report;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
// 1. Build Step
|
||||
try {
|
||||
console.log("Building parser from grammar, Master...");
|
||||
execSync('npm run build-parser');
|
||||
} catch (buildError) {
|
||||
console.error('Master, the parser build failed.');
|
||||
const report = generateBuildFailureReport(buildError);
|
||||
writeFileSync(resultsFile, report);
|
||||
console.log(`Failure report written to ${resultsFile}`);
|
||||
process.exit(1);
|
||||
return;
|
||||
throw { step: 'Build Step', error: buildError.stderr || buildError.message };
|
||||
}
|
||||
|
||||
// Build succeeded, now we can safely import and run tests.
|
||||
// 2. Transpiler Import & Test Execution
|
||||
const { hi2js } = await import('./transpiler.js');
|
||||
|
||||
const testFiles = readdirSync(srcDir).filter(file => file.endsWith('.hi'));
|
||||
@@ -129,6 +126,17 @@ async function run() {
|
||||
} else {
|
||||
console.log("All tests passed, Master.");
|
||||
}
|
||||
} catch (e) {
|
||||
// This is the global catch block for any fatal error.
|
||||
const step = e.step || 'Initialization Step';
|
||||
const error = e.error || e;
|
||||
console.error(`Master, a fatal error occurred during the ${step}.`);
|
||||
console.error(error);
|
||||
const report = generateCrashReport(error, step);
|
||||
writeFileSync(resultsFile, report);
|
||||
console.log(`Failure report written to ${resultsFile}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
Reference in New Issue
Block a user