Skip to content

refactor(cli): improve error handling for local script reading#1415

Open
mostuselessboy wants to merge 1 commit intogoogle:mainfrom
mostuselessboy:fix/local-script-errors
Open

refactor(cli): improve error handling for local script reading#1415
mostuselessboy wants to merge 1 commit intogoogle:mainfrom
mostuselessboy:fix/local-script-errors

Conversation

@mostuselessboy
Copy link

Suggests an improvement

This PR standardizes error handling while reading a local scripts, bringing all of it in line with the recent improvements made to remote script fetching made in this commit (#1408).

Usage demo

import {$} from 'zx'

// Before: RAW Node.js ENOENT stack trace
// After: Clean user error
await $`npx zx non-existent.mjs`
// stderr: Error: Can't read non-existent.mjs
//         Failed to read local script: non-existent.mjs (ENOENT...)
  • Build: I’ve run npm run build before committing and verified the bundle updates correctly.
  • Tests: I’ve run test (node --test test/cli.test.js) and confirmed the new assertions pass.
  • Docs: N/A (Internal error handling improvement).
  • Sign Commits have verified signatures and follow conventional commits spec
  • CoC: My changes follow the project’s coding guidelines and Code of Conduct.
  • Review: This PR represents original work and is not solely generated by AI tools.

@google-cla
Copy link

google-cla bot commented Feb 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mostuselessboy mostuselessboy force-pushed the fix/local-script-errors branch from 761b42d to 3ac91da Compare February 22, 2026 09:15
@mostuselessboy mostuselessboy force-pushed the fix/local-script-errors branch from 3ac91da to 9d4b5b9 Compare February 22, 2026 09:21
tempPath = getFilepath($.cwd, name, ext)
} else {
script = await fs.readFile(firstArg, 'utf8')
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Pull this into a separate function readScriptFromFile
  2. rm console.error. The exception will be caught and logged via main try-catch.
  3. Rollback scripts/*.mjs edits. Keep the PR purpose focus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants