2026-07-08 11:39:21 +08:00
|
|
|
import { sanitizeForOutput } from "./sanitize.js";
|
|
|
|
|
|
2026-03-13 18:57:50 +08:00
|
|
|
export function printResult(data: unknown, raw?: boolean): void {
|
2026-07-08 11:39:21 +08:00
|
|
|
// Neutralize any attacker-controlled metadata (token name/symbol/description/
|
|
|
|
|
// social links, on-chain URIs, etc.) before it is emitted and read by an AI
|
|
|
|
|
// agent. Defends against indirect prompt injection via token metadata.
|
|
|
|
|
const safe = sanitizeForOutput(data);
|
2026-03-13 18:57:50 +08:00
|
|
|
if (raw) {
|
2026-07-08 11:39:21 +08:00
|
|
|
console.log(JSON.stringify(safe));
|
2026-03-13 18:57:50 +08:00
|
|
|
} else {
|
2026-07-08 11:39:21 +08:00
|
|
|
console.log(JSON.stringify(safe, null, 2));
|
2026-03-13 18:57:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function exitOnError(err: Error): never {
|
|
|
|
|
console.error(`[gmgn-cli] ${err.message}`);
|
|
|
|
|
if (process.env.GMGN_DEBUG) {
|
|
|
|
|
if ((err as NodeJS.ErrnoException).code) {
|
|
|
|
|
console.error(`[gmgn-cli] code: ${(err as NodeJS.ErrnoException).code}`);
|
|
|
|
|
}
|
|
|
|
|
if ((err as { cause?: unknown }).cause) {
|
|
|
|
|
console.error(`[gmgn-cli] cause: ${(err as { cause?: unknown }).cause}`);
|
|
|
|
|
}
|
|
|
|
|
console.error(err.stack ?? "");
|
|
|
|
|
}
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|