yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: "Workspace not found" error isn't sent to stderr when running yarn, it's sent to stdout #4390

Open roiros opened 2 years ago

roiros commented 2 years ago

Self-service

Describe the bug

"Workspace not found" error isn't sent to stderr when running yarn, it's sent to stdout

To reproduce

note that some test platforms(like the playground referred at the docs (https://yarnpkg.com/playground) are running yarn1 when using the shell, it seems the shell integration for the bug report is running the correct version - yarn-berry

const fs = require('fs')
const child = require('child_process')

const topLevelPkg = {
  "name": "example",
  "private": true,
  "workspaces": [
    "packages/*"
  ],
}

const pkgA = 
{
  "name": "pkgA",
  "version": "1.0.0",
  "dependencies": {
    "pkgB": "workspaces:*"
  },
}
const pkgB = 
{
  "name": "pkgB",
  "version": "1.0.0",
}

fs.mkdirSync('packages')
fs.mkdirSync('packages/pkgA')
fs.mkdirSync('packages/pkgB')

fs.writeFileSync('package.json', JSON.stringify(topLevelPkg),'UTF-8')
fs.writeFileSync('packages/pkgA/package.json', JSON.stringify(pkgA), 'UTF-8')
fs.writeFileSync('packages/pkgB/package.json', JSON.stringify(pkgB), 'UTF-8')
await yarn('install')
fs.rmSync('packages/pkgB/package.json')
fs.rmdirSync('packages/pkgB')

const runResult = child.spawnSync('yarn')
//const yarn('install') //don't know how to get it's stderr (not stdout)
const errorOutputString = runResult.stderr.toString()
expect(errorOutputString).toContain(`Workspace not found`);

Environment

System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 16.14.0 - /private/var/folders/r5/y45bg5hs1fv5rh_1_nbv3d800000gp/T/xfs-2610965e/node
    Yarn: 3.2.0 - /private/var/folders/r5/y45bg5hs1fv5rh_1_nbv3d800000gp/T/xfs-2610965e/yarn
    npm: 6.14.11 - ~/Library/Caches/fnm_multishells/13341_1650801060709/bin/npm

Additional context

This illustrates usage of yarn3 The regular yarn shows the Workspace not found error When removing stdout, we see that the stderr is empty (but the exit code is 1)

roir@IL-C02DQ5S0MD6R~git2testt 2022-04-24 16-25-40

yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).toContain(expected) // indexOf

Expected substring: "Workspace not found"
Received string:    ""
    at module.exports (evalmachine.<anonymous>:43:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).toContain(expected) // indexOf

Expected substring: "Workspace not found"
Received string:    ""
    at module.exports (evalmachine.<anonymous>:43:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)