fix: decode console output to ensure tracebacks are detected even when encoded
This commit is contained in:
+31
-5
@@ -51,7 +51,8 @@ export function buildSubscribePath(hostname, shard) {
|
||||
*/
|
||||
export function detectTraceback(errorText) {
|
||||
if (!errorText) return false;
|
||||
return /^\s{4}at /m.test(errorText);
|
||||
const text = safeDecode(errorText);
|
||||
return /^\s{4}at /m.test(text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,22 @@ export function detectWarning(logLines) {
|
||||
return logLines.some((line) => warnPattern.test(line));
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely decodes a URI-encoded string from the Screeps console.
|
||||
* Returns the original string if decoding fails or if no '%' is present.
|
||||
*
|
||||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
export function safeDecode(text) {
|
||||
if (typeof text !== "string" || !text.includes("%")) return text;
|
||||
try {
|
||||
return decodeURIComponent(text);
|
||||
} catch (err) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
// Output helpers
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -166,11 +183,19 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||
if (detectWarning(logLines)) {
|
||||
state.sawWarningLog = true;
|
||||
const warnPattern = /<font\s+color=['"](?:orange|yellow)['"]/i;
|
||||
logLines.filter((l) => warnPattern.test(l)).forEach((l) => core.warning(l));
|
||||
logLines
|
||||
.filter((l) => warnPattern.test(l))
|
||||
.forEach((l) => core.warning(safeDecode(l)));
|
||||
}
|
||||
|
||||
// ── Traceback detection in log lines (Screeps sometimes sends errors here) ─
|
||||
if (logLines.some((l) => detectTraceback(l))) {
|
||||
state.sawTraceback = true;
|
||||
state.sawErrorLog = true;
|
||||
}
|
||||
|
||||
// ── Stdout lines ──────────────────────────────────────────────────────────
|
||||
const allStdout = [...logLines, ...results];
|
||||
const allStdout = [...logLines, ...results].map(safeDecode);
|
||||
if (allStdout.length > 0) {
|
||||
if (logToFile) {
|
||||
stdoutBuffer.push(...allStdout);
|
||||
@@ -182,8 +207,9 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||
// ── Error field (always live) ─────────────────────────────────────────────
|
||||
if (errorText) {
|
||||
state.sawErrorLog = true;
|
||||
core.error(errorText);
|
||||
if (detectTraceback(errorText)) {
|
||||
const decodedError = safeDecode(errorText);
|
||||
core.error(decodedError);
|
||||
if (detectTraceback(decodedError)) {
|
||||
state.sawTraceback = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user