feat: add semantic CLI exit codes

This commit is contained in:
gitea committed 2026-09-11 17:11:51 +08:00
1 parent 45eb83a609
commit a5c0146c8d
5 files changed
+93 -10

No files matched your search

+4 -2
View File
@@ -1,6 +1,7 @@
import { writeFileSync } from "node:fs";
import { VERSION } from "../version.js";
import type { OutputOptions } from "./types.js";
import { PayloadTooLargeError } from "./errors.js";
export const DEFAULT_OUTPUT_BYTES_LIMIT = 200_000;
@@ -15,8 +16,9 @@ export function protectLargeOutput(result: unknown, options: OutputOptions = {})
if (options.allowFull || options.outputFile) return;
const bodyBytes = Buffer.byteLength(JSON.stringify(result), "utf-8");
if (bodyBytes > DEFAULT_OUTPUT_BYTES_LIMIT) {
throw new Error(
`输出体积过大 (${bodyBytes} 字节,超过安全阈值 ${DEFAULT_OUTPUT_BYTES_LIMIT} 字节)。请使用 --output-file <路径> (或 -o <路径>) 转储到本地文件;若确需完整大报文请附加 --full 参数。`
throw new PayloadTooLargeError(
`输出体积过大 (${bodyBytes} 字节,超过安全阈值 ${DEFAULT_OUTPUT_BYTES_LIMIT} 字节)。请使用 --output-file <路径> (或 -o <路径>) 转储到本地文件;若确需完整大报文请附加 --full 参数。`,
"hose-use <command> --json --output-file <path>"
);
}
}