Skip to content

Commit 54c96c8

Browse files
committed
build: safeguard terminal styling in devkit admin script
Prior to this change, if an unhandled promise rejection or error occurred that lacked a `stack` property, the `console.error` wrapper in `devkit-admin.mts` would receive `undefined`. Attempting to pass `undefined` to Node`s `util.styleText` caused an unexpected `ERR_INVALID_ARG_TYPE` crash instead of printing the original error. This commit updates the `console.warn` and `console.error` overrides to ensure they only apply `styleText` to strings. It also updates the top-level try-catch block to fallback to the original error object if `err.stack` is undefined, preventing silent suppression.
1 parent a5ab23e commit 54c96c8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scripts/devkit-admin.mts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ process.chdir(path.join(scriptDir, '..'));
3333

3434
const originalConsole = { ...console };
3535
console.warn = function (...args) {
36-
const [m, ...rest] = args;
37-
originalConsole.warn(styleText(['yellow'], m), ...rest);
36+
if (typeof args[0] === 'string') {
37+
args[0] = styleText(['yellow'], args[0]);
38+
}
39+
originalConsole.warn(...args);
3840
};
3941
console.error = function (...args) {
40-
const [m, ...rest] = args;
41-
originalConsole.error(styleText(['red'], m), ...rest);
42+
if (typeof args[0] === 'string') {
43+
args[0] = styleText(['red'], args[0]);
44+
}
45+
originalConsole.error(...args);
4246
};
4347

4448
try {
@@ -47,6 +51,6 @@ try {
4751
process.exitCode = typeof exitCode === 'number' ? exitCode : 0;
4852
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4953
} catch (err: any) {
50-
console.error(err.stack);
54+
console.error(err.stack ?? err);
5155
process.exitCode = 99;
5256
}

0 commit comments

Comments
 (0)