feat(code): add opencode#2962
Conversation
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
Reviews (1): Last reviewed commit: "feat(code): add opencode" | Re-trigger Greptile |
| } catch { | ||
| // npx cache absent — fine. | ||
| } | ||
| return found.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs); |
There was a problem hiding this comment.
The
fs.statSync calls inside the sort comparator sit outside the surrounding try/catch. readdirSync and existsSync are guarded, but the subsequent sort is not. If any file in found is deleted or becomes inaccessible between the existsSync check and the statSync call (e.g., a concurrent npm operation flushes the npx cache), the sort throws synchronously and propagates through resolveOpencodeBinaryPath — preventing getOpencodeBinaryPath() from returning the bundled binary path even when it exists, and causing session initialization to fail.
| return found.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs); | |
| try { | |
| return found.sort( | |
| (a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs, | |
| ); | |
| } catch { | |
| return found; | |
| } |
| if (options.length === 0) return option; | ||
| const isGroup = "group" in options[0]; | ||
|
|
||
| if (isGroup) { |
There was a problem hiding this comment.
The
isGroup flag is set by inspecting only options[0]. If opencode ever returns a mixed-shape array — even one flat option following a group — all entries after the first will be cast to the wrong type. In the flat branch, isPosthogModel(opt) accesses opt.value which is undefined for group objects, throwing a TypeError. Using Array.prototype.every gives a safe exhaustive guard at negligible cost.
| if (options.length === 0) return option; | |
| const isGroup = "group" in options[0]; | |
| if (isGroup) { | |
| if (options.length === 0) return option; | |
| const isGroup = options.every((o) => "group" in o); | |
| if (isGroup) { |

Problem
Changes
How did you test this?
Automatic notifications