feat: support multiline console output and decode HTML entities
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+33
-8
@@ -76,12 +76,37 @@ export function detectWarning(logLines) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function safeDecode(text) {
|
export function safeDecode(text) {
|
||||||
if (typeof text !== "string" || !text.includes("%")) return text;
|
if (typeof text !== "string") return text;
|
||||||
try {
|
let result = text;
|
||||||
return decodeURIComponent(text);
|
if (result.includes("%")) {
|
||||||
} catch (err) {
|
try {
|
||||||
return text;
|
result = decodeURIComponent(result);
|
||||||
|
} catch (err) {
|
||||||
|
// Ignore decoding errors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Screeps console often contains HTML entities
|
||||||
|
return result
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/&/g, "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs text to the action log, splitting by newline to ensure proper display.
|
||||||
|
*
|
||||||
|
* @param {string} text
|
||||||
|
* @param {"info"|"warning"|"error"} level
|
||||||
|
*/
|
||||||
|
export function outputMultiline(text, level = "info") {
|
||||||
|
if (!text) return;
|
||||||
|
const lines = text.split(/\r?\n/);
|
||||||
|
lines.forEach((line) => {
|
||||||
|
if (level === "error") core.error(line);
|
||||||
|
else if (level === "warning") core.warning(line);
|
||||||
|
else core.info(line);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ────────────────────────────────────────────────────────────────────────────
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
@@ -185,7 +210,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
|||||||
const warnPattern = /<font\s+color=['"](?:orange|yellow)['"]/i;
|
const warnPattern = /<font\s+color=['"](?:orange|yellow)['"]/i;
|
||||||
logLines
|
logLines
|
||||||
.filter((l) => warnPattern.test(l))
|
.filter((l) => warnPattern.test(l))
|
||||||
.forEach((l) => core.warning(safeDecode(l)));
|
.forEach((l) => outputMultiline(safeDecode(l), "warning"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Traceback detection in log lines (Screeps sometimes sends errors here) ─
|
// ── Traceback detection in log lines (Screeps sometimes sends errors here) ─
|
||||||
@@ -200,7 +225,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
|||||||
if (logToFile) {
|
if (logToFile) {
|
||||||
stdoutBuffer.push(...allStdout);
|
stdoutBuffer.push(...allStdout);
|
||||||
} else {
|
} else {
|
||||||
allStdout.forEach((l) => core.info(l));
|
allStdout.forEach((l) => outputMultiline(l, "info"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +233,7 @@ export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
|||||||
if (errorText) {
|
if (errorText) {
|
||||||
state.sawErrorLog = true;
|
state.sawErrorLog = true;
|
||||||
const decodedError = safeDecode(errorText);
|
const decodedError = safeDecode(errorText);
|
||||||
core.error(decodedError);
|
outputMultiline(decodedError, "error");
|
||||||
if (detectTraceback(decodedError)) {
|
if (detectTraceback(decodedError)) {
|
||||||
state.sawTraceback = true;
|
state.sawTraceback = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user