fix: add BUILD_TAG to bridge so we can verify which code is running
If you see [v2-debug] in the log, you're on the new code. If you don't, you're still on main and the old error handler is hiding the real error. Also hardened the fatal catch handler to never crash on weird error values.
This commit is contained in:
@@ -46,8 +46,10 @@ function err(msg: string): void {
|
||||
console.error(`[ksp-bridge] ${msg}`);
|
||||
}
|
||||
|
||||
const BUILD_TAG = 'v2-debug';
|
||||
|
||||
async function main(): Promise<void> {
|
||||
log(`config: api=${API_URL} host=${HOST}:${RPC_PORT} poll=${POLL_MS}ms`);
|
||||
log(`config: api=${API_URL} host=${HOST}:${RPC_PORT} poll=${POLL_MS}ms} [${BUILD_TAG}]`);
|
||||
|
||||
// First, try to connect to a real kRPC server. If it works, run
|
||||
// the real extract loop. If it fails, fall back to mock mode.
|
||||
@@ -60,8 +62,28 @@ async function main(): Promise<void> {
|
||||
await adapter.connect();
|
||||
log(`connected to kRPC at ${HOST}:${RPC_PORT} — running with real KSP state`);
|
||||
} catch (e) {
|
||||
const msg = e === null ? 'null' : e instanceof Error ? e.message : String(e);
|
||||
log(`no kRPC server at ${HOST}:${RPC_PORT}: ${msg}`);
|
||||
// Hardened error formatter: handles null, undefined, Error,
|
||||
// strings, and arbitrary objects. Never crashes the formatter
|
||||
// itself, so we always see *something*.
|
||||
let msg: string;
|
||||
if (e === null) {
|
||||
msg = 'null';
|
||||
} else if (e === undefined) {
|
||||
msg = 'undefined';
|
||||
} else if (typeof e === 'string') {
|
||||
msg = e;
|
||||
} else if (e instanceof Error) {
|
||||
msg = e.message;
|
||||
} else if (typeof e === 'object') {
|
||||
try {
|
||||
msg = JSON.stringify(e);
|
||||
} catch {
|
||||
msg = String(e);
|
||||
}
|
||||
} else {
|
||||
msg = String(e);
|
||||
}
|
||||
log(`[${BUILD_TAG}] no kRPC server at ${HOST}:${RPC_PORT}: ${msg}`);
|
||||
log('Falling back to MOCK mode (synthetic state).');
|
||||
return runMock();
|
||||
}
|
||||
@@ -165,6 +187,14 @@ function mockState(ut: number): ExtractedState {
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
err(`fatal: ${e}`);
|
||||
let msg: string;
|
||||
if (e === null) msg = 'null';
|
||||
else if (e === undefined) msg = 'undefined';
|
||||
else if (e instanceof Error) msg = `${e.message} (stack: ${e.stack ?? 'n/a'})`;
|
||||
else if (typeof e === 'string') msg = e;
|
||||
else if (typeof e === 'object') {
|
||||
try { msg = JSON.stringify(e); } catch { msg = String(e); }
|
||||
} else msg = String(e);
|
||||
err(`fatal: ${msg}`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user