Skip to content

Commit fac5336

Browse files
committed
fix: error output not being properly formatted
1 parent d9f3c44 commit fac5336

File tree

2 files changed

+64
-22
lines changed

2 files changed

+64
-22
lines changed

src/controllers/errorController.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,41 @@ Provide analysis including:
9999
aiAnalysis = { error: "AI analysis unavailable" };
100100
}
101101

102-
// Enrich each error with a more friendly message (removing detailed stack traces).
103-
const enrichedErrors: ErrorItem[] = errors.map((err: ErrorItem) => {
104-
const severity = categorizeError(err.message);
105-
let emoji: string;
106-
switch (severity) {
107-
case "High":
108-
emoji = "🚨";
109-
break;
110-
case "Medium":
111-
emoji = "🔔";
112-
break;
113-
default:
114-
emoji = "ℹ️";
115-
break;
102+
// Ensure errors are in the correct format
103+
const normalizedErrors = errors.map((err: ErrorItem) => ({
104+
message: typeof err === "string" ? err : err.message,
105+
stack: err.stack || "",
106+
readableMessage: err.readableMessage || "",
107+
}));
108+
109+
// Enrich each error with a more friendly message
110+
const enrichedErrors: ErrorItem[] = normalizedErrors.map(
111+
(err: ErrorItem, index: number) => {
112+
const severity = categorizeError(err.message);
113+
let emoji: string;
114+
switch (severity) {
115+
case "High":
116+
emoji = "🚨";
117+
break;
118+
case "Medium":
119+
emoji = "🔔";
120+
break;
121+
default:
122+
emoji = "ℹ️";
123+
break;
124+
}
125+
return {
126+
...err,
127+
readableMessage: `${emoji} Test Error [${index + 1}]: ${err.message}`,
128+
};
116129
}
117-
return {
118-
...err,
119-
readableMessage: `${emoji} ${severity} severity error: ${err.message}`,
120-
};
121-
});
130+
);
131+
132+
const processedError: ProcessedError = {
133+
type: type || "errorBatch",
134+
errors: enrichedErrors,
135+
timestamp: timestamp || new Date().toISOString(),
136+
};
122137

123138
// Determine the highest severity among reported errors.
124139
const highestSeverity = enrichedErrors

src/services/zeromqService.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,21 @@ async function delay(ms: number): Promise<void> {
8888
function createErrorSummary(errors: ErrorObject[]): string {
8989
return errors
9090
.map((err: ErrorObject, index: number) => {
91-
const message = err.readableMessage || err.message || "N/A";
92-
return ` ${index + 1}. ${message}`;
91+
// Use the readableMessage if available, otherwise create one
92+
if (!err.readableMessage) {
93+
const severity = categorizeError(err.message || "");
94+
let emoji = "️ℹ️";
95+
switch (severity.toLowerCase()) {
96+
case "high":
97+
emoji = "🚨";
98+
break;
99+
case "medium":
100+
emoji = "⚠️";
101+
break;
102+
}
103+
err.readableMessage = `${emoji} Test Error [${index + 1}]: ${err.message}`;
104+
}
105+
return `${index + 1}. ${err.readableMessage}`;
93106
})
94107
.join("\n");
95108
}
@@ -157,6 +170,20 @@ async function initializeServer() {
157170
continue;
158171
}
159172

173+
// Normalize the errors
174+
parsedMessage.errors = parsedMessage.errors.map(
175+
(err: any, index: number) => {
176+
const errorObj = typeof err === "string" ? { message: err } : err;
177+
return {
178+
message: errorObj.message || "Unknown error",
179+
stack: errorObj.stack || "",
180+
readableMessage:
181+
errorObj.readableMessage ||
182+
`Test Error [${index + 1}]: ${errorObj.message}`,
183+
};
184+
}
185+
);
186+
160187
const errorSummary = createErrorSummary(parsedMessage.errors);
161188
const formattedTime = formatTimestamp(parsedMessage.timestamp);
162189
const overallSeverity =
@@ -182,7 +209,7 @@ async function initializeServer() {
182209
// Send initial error report first and wait for confirmation
183210
const initialMessage = `🚨 New Error Report
184211
185-
Type: ${parsedMessage.type}
212+
Type: ${parsedMessage.type || "errorBatch"}
186213
Time: ${formattedTime}
187214
Overall Severity: ${overallSeverity} ${severityEmoji}
188215

0 commit comments

Comments
 (0)