{"record":{"id":"cb5eb36916cf17cc","repo":"google/zx","slug":"no-script-provided","errorCode":null,"errorMessage":"No script provided","messagePattern":"No script provided","errorType":"exception","errorClass":"Fail","httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":221,"sourceCode":"\nasync function readScript() {\n  const [firstArg] = argv._\n  let script = ''\n  let scriptPath = ''\n  let tempPath = ''\n  let argSlice = 1\n\n  if (argv.eval) {\n    argSlice = 0\n    script = argv.eval\n    tempPath = getFilepath($.cwd, 'zx', argv.ext)\n  } else if (!firstArg || firstArg === '-') {\n    script = await readScriptFromStdin()\n    tempPath = getFilepath($.cwd, 'zx', argv.ext)\n    if (script.length === 0) {\n      printUsage()\n      process.exitCode = 1\n      throw new Fail('No script provided')\n    }\n  } else if (/^https?:/.test(firstArg)) {\n    const { name, ext = argv.ext } = path.parse(new URL(firstArg).pathname)\n    script = await readScriptFromHttp(firstArg)\n    tempPath = getFilepath($.cwd, name, ext)\n  } else {\n    script = await fs.readFile(firstArg, 'utf8')\n    scriptPath = firstArg.startsWith('file:')\n      ? url.fileURLToPath(firstArg)\n      : path.resolve(firstArg)\n  }\n\n  const { ext, base, dir } = path.parse(tempPath || scriptPath)\n  if (ext === '' || (argv.ext && !EXT_RE.test(ext))) {\n    tempPath = getFilepath(dir, base)\n  }\n  if (ext === '.md') {\n    script = transformMarkdown(script)","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/google/zx/blob/00a2c484e219c2e84bfc3a199febf7fbce2cfbf4/src/cli.ts#L203-L239","documentation":"Thrown by readScript() in the zx CLI when no script source could be obtained: no positional file argument, no --eval, no http(s) URL, and stdin produced zero bytes (or is a TTY). zx needs a script to run, so after printing usage it exits with code 1.","triggerScenarios":"Invoking `zx` with no arguments in an interactive terminal (stdin is a TTY); `echo -n '' | zx` or piping an empty stream; `zx -` with empty stdin; a CI job that forgot to pass the script path.","commonSituations":"Forgetting the script path; misconfigured shell pipe that sends no data; wrapper script that conditionally drops the file argument; Docker ENTRYPOINT missing the script.","solutions":["Pass a script file path: `zx script.mjs`.","Use --eval / -e to provide inline code: `zx -e \"console.log('hi')\"`.","Pipe actual script content: `cat script.mjs | zx`.","Fetch from a URL: `zx https://example.com/script.mjs`."],"exampleFix":"// before\n$ zx\n// after\n$ zx ./build.mjs","handlingStrategy":"validation","validationCode":"function resolveScriptSource(argv, isTTY: boolean): 'file' | 'eval' | 'url' | 'stdin' | null {\n  if (argv.eval) return 'eval'\n  const [first] = argv._\n  if (first && /^https?:/.test(first)) return 'url'\n  if (first && first !== '-') return 'file'\n  if (!isTTY) return 'stdin'\n  return null // nothing to read -> would throw 'No script provided'\n}\n\nif (resolveScriptSource(argv, process.stdin.isTTY!) === null) {\n  printUsage(); process.exit(1)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await main()\n} catch (e) {\n  if (e instanceof Fail && /No script provided/.test(e.message)) {\n    console.error('Pass a file, -e <code>, a URL, or pipe a script via stdin.')\n    process.exitCode = 1\n  } else throw e\n}","preventionTips":["Always pass an explicit script path or -e expression in CI.","When piping, assert the stream is non-empty before invoking zx.","Treat an interactive TTY with no args as a usage error at the wrapper level."],"tags":["cli","stdin","usage","argv"],"backgroundTag":null,"analyzedSha":"00a2c484e219c2e84bfc3a199febf7fbce2cfbf4","analyzedAt":"2026-08-13T02:11:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}