yarnpkg / berry

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

[Bug] plugin-version error when running in quick succession #1300

Open zypA13510 opened 4 years ago

zypA13510 commented 4 years ago

Describe the bug

While running yarn workspace <name> version patch in quick succession, the command may succeed for the first few workspaces, but quickly followed by this error for subsequent workspaces:

➤ YN0000: Internal Error: Assertion failed: Expected a release definition file to only reference existing workspaces (d6c45c39.yml references 0) ➤ YN0000: at Object.resolveVersionFiles (/home/user/project/.yarn/plugins/@yarnpkg/plugin-version.js:401:39) ➤ YN0000: at async VersionCommand.execute (/home/user/project/.yarn/plugins/@yarnpkg/plugin-version.js:34740:26) ➤ YN0000: at async VersionCommand.validateAndExecute (/home/user/project/.yarn/releases/yarn-berry.js:16:50176) ➤ YN0000: at async c.run (/home/user/project/.yarn/releases/yarn-berry.js:42:55029) ➤ YN0000: at async runCommand (/home/user/project/.yarn/plugins/@yarnpkg/plugin-workspace-tools.js:409:31) ➤ YN0000: at async /home/user/project/.yarn/plugins/@yarnpkg/plugin-workspace-tools.js:456:32

Removing .yarn/versions/ and then re-run for failed workspaces will again be successful for the first few workspaces.

To Reproduce

Both the following will fail:

echo @foo/{a,b,c} | tr " " "\n" | xargs -I% yarn workspace % version patch
yarn workspaces foreach version patch
Reproduction ```js repro await packageJson({ "name": "workspace", "private": true, "workspaces": [ "packages/*" ] }) await packageJson({ "name": "@foo/a", "version": "0.1.0", }, {cwd: './packages/a'}) await packageJson({ "name": "@foo/b", "version": "0.1.0", "dependencies": { "@foo/a": "workspace:>= 0.1 < 1" } }, {cwd: './packages/b'}) await packageJson({ "name": "@foo/c", "version": "0.1.0", "dependencies": { "@foo/b": "workspace:>= 0.1 < 1" } }, {cwd: './packages/c'}) await yarn('install') await ['a', 'b', 'c'].reduce(async (promise, pkg) => { await promise await expect(yarn('workspace', `@foo/${pkg}`, 'version', 'patch')).resolves.toBeDefined() }, Promise.resolve()) ;['a', 'b', 'c'].forEach(x => expect(require(`./packages/${x}/package.json`)).toHaveProperty('version', '0.1.1')) ```

Screenshots

If applicable, add screenshots to help explain your problem.

Environment if relevant (please complete the following information):

Additional context

Reproduction not running due to #1302 please re-run repro @yarnbot

yarnbot commented 4 years ago

The reproduction case in your issue seems broken (ie it neither pass nor fail due to throwing an unmanaged exception):

Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js plugin import version

Usage Error: This plugin cannot access the package referenced via @yarnpkg/cli which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-workspace-tools, defined in /tmp/tmp-27iJEFQIlD3o2R/.yarnrc.yml)

Yarn Package Manager - 2.0.0-rc.33

  $ yarn <command>

You can also print more details about any of these commands by calling them 
after adding the `-h,--help` flag right after the command name.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Remember: any non-Jest exceptions will cause the test to be reported as broken. If you expect something to pass without throwing, you must wrap it into something like await expect(...).resolves.toBeTruthy(). If you instead expect something to throw, you need to wrap it into await expect(...).rejects.toThrow().

yarnbot commented 4 years ago

The reproduction case in your issue seems broken (ie it neither pass nor fail due to throwing an unmanaged exception):

Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js plugin import version

Usage Error: This plugin cannot access the package referenced via @yarnpkg/cli which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-workspace-tools, defined in /tmp/tmp-27Bl43mNlK0wlF/.yarnrc.yml)

Yarn Package Manager - 2.0.0-rc.33

  $ yarn <command>

You can also print more details about any of these commands by calling them 
after adding the `-h,--help` flag right after the command name.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Remember: any non-Jest exceptions will cause the test to be reported as broken. If you expect something to pass without throwing, you must wrap it into something like await expect(...).resolves.toBeTruthy(). If you instead expect something to throw, you need to wrap it into await expect(...).rejects.toThrow().

zypA13510 commented 4 years ago

The reproduction case in your issue seems broken (ie it neither pass nor fail due to throwing an unmanaged exception):

Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js plugin import version

Usage Error: This plugin cannot access the package referenced via @yarnpkg/cli which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-workspace-tools, defined in /tmp/tmp-27Bl43mNlK0wlF/.yarnrc.yml)

Yarn Package Manager - 2.0.0-rc.33

  $ yarn <command>

You can also print more details about any of these commands by calling them 
after adding the `-h,--help` flag right after the command name.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Remember: any non-Jest exceptions will cause the test to be reported as broken. If you expect something to pass without throwing, you must wrap it into something like await expect(...).resolves.toBeTruthy(). If you instead expect something to throw, you need to wrap it into await expect(...).rejects.toThrow().

Reported as #1302

yarnbot commented 4 years ago

The reproduction case in your issue seems broken (ie it neither pass nor fail due to throwing an unmanaged exception):

Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js plugin import version

Usage Error: This plugin cannot access the package referenced via @yarnpkg/cli which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-workspace-tools, defined in /tmp/tmp-2753tSBxYANJ7s/.yarnrc.yml)

Yarn Package Manager - 2.0.0-rc.33

  $ yarn <command>

You can also print more details about any of these commands by calling them 
after adding the `-h,--help` flag right after the command name.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Remember: any non-Jest exceptions will cause the test to be reported as broken. If you expect something to pass without throwing, you must wrap it into something like await expect(...).resolves.toBeTruthy(). If you instead expect something to throw, you need to wrap it into await expect(...).rejects.toThrow().

yarnbot commented 4 years ago

The reproduction case in your issue seems broken (ie it neither pass nor fail due to throwing an unmanaged exception):

TypeError: Cannot read property 'forEach' of undefined
    at module.exports (evalmachine.<anonymous>:37:16)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-3.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-3.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-3.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)

Remember: any non-Jest exceptions will cause the test to be reported as broken. If you expect something to pass without throwing, you must wrap it into something like await expect(...).resolves.toBeTruthy(). If you instead expect something to throw, you need to wrap it into await expect(...).rejects.toThrow().

yarnbot commented 4 years ago

This issue reproduces on master:

Error: expect(received).rejects.not.toThrow()

Received promise resolved instead of rejected
Resolved to value: "➤ YN0000: @foo/a@workspace:packages/a: Bumped to 0.1.1
➤ YN0000: Couldn't auto-upgrade range >= 0.1 < 1 (in @foo/a@workspace:packages/a)
➤ YN0000: ┌ Resolution step
::group::Resolution step
::endgroup::
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
::group::Fetch step
::endgroup::
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
::group::Link step
::endgroup::
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 0.06s
"
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-3.zip/node_modules/expect/build/index.js:138:15)
    at evalmachine.<anonymous>:35:9
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async evalmachine.<anonymous>:34:3
    at async evalmachine.<anonymous>:34:3
    at async module.exports (evalmachine.<anonymous>:33:1)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
yarnbot commented 4 years ago

This issue reproduces on master:

Error: expect(received).resolves.toBeDefined()

Received promise rejected instead of resolved
Rejected to value: [Error: Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js workspace @foo/c version patch

Internal Error: Assertion failed: Expected a release definition file to only reference existing workspaces (4c71a585.yml references 0)
    at Object.resolveVersionFiles (/github/workspace/packages/plugin-version/sources/versionUtils.ts:126:15)
    at VersionCommand.execute (/github/workspace/packages/plugin-version/sources/commands/version.ts:110:24)
    at VersionCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.1.5-aef0ebbd62-3.zip/node_modules/clipanion/lib/advanced/Command.js:182:26)
    at Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.1.5-aef0ebbd62-3.zip/node_modules/clipanion/lib/advanced/Cli.js:85:24)
    at WorkspaceCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.1.5-aef0ebbd62-3.zip/node_modules/clipanion/lib/advanced/Command.js:182:26)
    at Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.1.5-aef0ebbd62-3.zip/node_modules/clipanion/lib/advanced/Cli.js:85:24)
    at Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.1.5-aef0ebbd62-3.zip/node_modules/clipanion/lib/advanced/Cli.js:94:28)
]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-3.zip/node_modules/expect/build/index.js:138:15)
    at evalmachine.<anonymous>:35:9
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async module.exports (evalmachine.<anonymous>:33:1)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-1.0.38-d4f5e2dbf3-3.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-3.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-3.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
mxro commented 4 years ago

Encountered the same issue with 2.0.0-rc.34 running yarn workspaces foreach ... in an GitHub action (see below).

I could come up with the following workaround:

This seems to resolve the issue for me.

 YN0000: Internal Error: Assertion failed: Expected a release definition file to only reference existing workspaces (babe3532.yml references 0)
➤ YN0000:     at p (/home/runner/work/goldstack/goldstack/.yarn/plugins/@yarnpkg/plugin-version.cjs:53:1075)
➤ YN0000:     at async A.execute (/home/runner/work/goldstack/goldstack/.yarn/plugins/@yarnpkg/plugin-version.cjs:53:21560)
➤ YN0000:     at async A.validateAndExecute (/home/runner/work/goldstack/goldstack/.yarn/releases/yarn-berry.js:25:318779)
➤ YN0000:     at async e.run (/home/runner/work/goldstack/goldstack/.yarn/releases/yarn-berry.js:31:458286)
➤ YN0000:     at async e.runExit (/home/runner/work/goldstack/goldstack/.yarn/releases/yarn-berry.js:31:458420)