fix: list 结果过大导致 CLI 崩溃 & --endpoint 命令行参数不生效 - #168
Conversation
`s cli fc3 list` crashed with "Maximum call stack size exceeded" whenever the listing was large: the CLI core renders a component's return value with prettyjson, which flattens the whole payload into one array of lines and re-injects it via `push.apply(lines, subLines)`. Past the V8 argument limit (~120k, measured on Node 22) that throws a RangeError. A real listing of 3793 functions renders to ~182k lines, so it always crashed after ~70s of paging. The list result now falls back to printing raw JSON (with a hint about --limit/--next-token, --table and -o json/yaml) when it would exceed the renderer's limit. The guard only applies to the CLI's default render path: --output-format/--output/--output-file and programmatic app center callers keep the return value untouched. estimateRenderLines is validated against prettyjson 1.2.5: it underestimates the real list payload by ~7% and by at most 25% on the worst shape, so the 50k threshold maps to ~62k actual lines, well below the limit.
Every subcommand reads the endpoint from `inputs.props.endpoint`, which is only populated from s.yaml. In `s cli` mode there is no yaml, so `--endpoint` was parsed into argv and then silently ignored: `s cli fc3 list --endpoint http://...` still went to the public `fcv3.<region>.aliyuncs.com` instead of the requested cluster, and only FC_CLIENT_CUSTOM_ENDPOINT worked. handlePreRun now reads --endpoint from argv and writes it into props.endpoint, so the command line takes precedence over yaml. The option is documented in the `list` help text.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe list command now avoids oversized default-renderer output by writing raw JSON. New utilities detect output modes and estimate rendered lines. The base command now propagates a command-line endpoint, and list help documents the option. ChangesList output handling
Command-line endpoint handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: 🔵 Low · up to The change adds CLI endpoint override behavior for list operations with YAML fallback. It is generally mergeable, but the parser should be confirmed to forward string values and reject a missing endpoint value; otherwise an invalid invocation could cause incorrect command behavior. Sequence Diagram(s)sequenceDiagram
participant ListCommand
participant RenderUtils
participant Logger
ListCommand->>RenderUtils: Detect output mode
ListCommand->>RenderUtils: Estimate rendered lines
alt Oversized default output
ListCommand->>Logger: Write warning and formatted JSON
else Small or explicit-format output
ListCommand-->>ListCommand: Return result
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
`index.ts#list` returns it from an exported class, and tsconfig has `declaration: true`, so tsc needs the type to be nameable: TS4053 "Return type of public method from exported class has or is using name 'IListResult' ... but cannot be named".
问题
在一个函数数量很多的地域执行
s cli fc3 list --prefix <prefix> --region <region> --endpoint <custom endpoint>,命令报错退出:排查出两个独立的 bug。
1. list 结果过大时 CLI 崩溃
~/.s/logs/*/s_cli.log的调用栈直指内核渲染路径:Et.output→Sk.render→Lx→Array.forEach。内核用 prettyjson 渲染组件返回值,prettyjson 把整个返回值拍平成一个字符串数组,再用push.apply(lines, subLines)回灌,参数个数超过 V8 上限(本机 Node 22 实测 12w 个参数可以、13w 抛错)就抛RangeError。复现时结果集是几千个函数(
-o json约 8MB),prettyjson 实际渲染约 18 万行,必然崩溃 —— 而且是在完整分页一分多钟之后才崩,等于白等。2.
--endpoint命令行参数被静默忽略日志里
list opts能看到endpoint,紧接着却是get custom endpoint: undefined、endpoint=fcv3.<region>.aliyuncs.com。原因是所有子命令都从inputs.props.endpoint取值,而它只由 s.yaml 填充;s cli模式没有 yaml,参数就丢了。所以请求实际打到了默认公网地址而不是指定的 endpoint,之前只有FC_CLIENT_CUSTOM_ENDPOINT或 s.yaml 有效。改动
list 渲染兜底(
src/subCommands/list/index.ts、src/utils/index.ts)--table返回路径改走output():预估渲染行数超过MAX_DEFAULT_RENDER_LINES(5w) 时,直接logger.write(JSON.stringify(...))打印,并提示可用--limit/--next-token、--table、-o json/yaml。-o/--output-format/--output/--output-file,以及 app center 等程序化调用(isAppCenter())时原样返回,不破坏返回值契约。estimateRenderLines用 prettyjson 1.2.5 实测校准:对每个非标量数组元素补一行(prettyjson 的分隔行)后,对 list 返回值低估约 7%,最坏结构形状低估 25%,即 5w 阈值对应实际最多约 6.2w 行,距 12w 上限有 2x 余量。--endpoint生效(src/base.ts、src/commands-help/list.ts)handlePreRun从 argv 解析--endpoint写入props.endpoint,命令行优先于 yaml;list帮助文本补上该选项。model作用域不读props.endpoint,行为未变;deploy/impl/function.ts、plan/index.ts本就会unset掉它。Test plan
list_test/base_test/utils_functions_test—— 81 tests 全通过(新增 11 条)-o json时原样返回、小结果原样返回、app center 原样返回、单页--limit路径同样受保护isDefaultRenderOutput各种 flag 形态(含--output-format=json、--prefix output不误判)、estimateRenderLines标量/嵌套/数组分隔行/阈值上下npm test(__tests__/ut):70/75 suites、1046 passed、2 skippednpm run lint:0 errors(唯一 warning 在未改动的src/resources/fc/impl/utils.ts:48,既有)npx tsc --noEmit:仓库src/0 错误prettier --check改动文件全部通过npm run build(ncc):本地环境装不全依赖,需 CI 验证--endpoint生效且大结果不再崩溃Summary by CodeRabbit
New Features
--endpoint.Bug Fixes
Documentation