Skip to content

Commit 9cf83d9

Browse files
author
Haider
committed
stdin: use optional chaining for process.stdin NPE guard
Matches the literal form suryaiyer95 proposed in review #3 on PR #935: `process.stdin?.isTTY` instead of an early-return + plain access. Functionally equivalent — the fstat try/catch already returns "" when fd 0 isn't open, so the optional chaining alone covers the embedded- runtime case.
1 parent 7fceb85 commit 9cf83d9

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

packages/opencode/src/util/stdin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ function defaultWarn(msg: string): void {
7777
// slow-producer case.
7878
export async function readStdinIfAvailable(deps: ReadStdinDeps = {}): Promise<string> {
7979
// `process.stdin` can be undefined in embedded / child runtimes (flagged
80-
// by dev-punia on PR #937). Treat absence as "no stdin to read."
81-
if (deps.isTTY === undefined && !process.stdin) return ""
82-
83-
const isTTY = deps.isTTY ?? Boolean(process.stdin.isTTY)
80+
// by dev-punia on PR #937, suryaiyer95 review on PR #935 #3). Optional
81+
// chaining keeps the access safe; the fstat catch below covers the case
82+
// where fd 0 itself isn't open.
83+
const isTTY = deps.isTTY ?? Boolean(process.stdin?.isTTY)
8484
const fstat = deps.fstat ?? (() => fs.fstatSync(0) as Stat)
8585
const readStdin = deps.readStdin ?? defaultReadStdin
8686
const timeoutMs = deps.timeoutMs ?? resolveTimeoutMs()

0 commit comments

Comments
 (0)