Skip to content

Commit b1f21a8

Browse files
CGamesPlayarcanis
authored andcommitted
Show problem path in invariant message (#6868)
Sometimes, `yarn add` will fail unexpectedly, and it leaves the cache in an invalid state. To cause your yarn cache to become corrupted: ``` $ yarn add [email protected] yarn add v1.12.3 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... error https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.6.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "Unexpected end of data" info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. $ yarn cache list yarn cache v1.12.3 error An unexpected error occurred: "There should only be one folder in a package cache (got )". info If you think this is a bug, please open a bug report with the information provided in "/Users/rpatterson/Projects/chess2/www2/client/yarn-error.log". info Visit https://yarnpkg.com/en/docs/cli/cache for documentation about this command. ``` Note that the error message provides no information about how to resolve the error. This commit adds the problem path to the invariant message. Deleting this problem path will allow `yarn cache list` to work properly again. The root cause of this issue is yarn#6805 which has been closed. This commit does not resolve the issue, so that issue should likely be reopened.
1 parent 960141d commit b1f21a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/cli/commands/cache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function getCachedPackagesDirs(config: Config, currentPath: string)
3131
const candidates = await fs.readdir(packageParentPath);
3232
invariant(
3333
candidates.length === 1,
34-
`There should only be one folder in a package cache (got ${candidates.join(',')})`,
34+
`There should only be one folder in a package cache (got ${candidates.join(',')} in ${packageParentPath})`,
3535
);
3636

3737
for (const candidate of candidates) {
@@ -40,7 +40,7 @@ export async function getCachedPackagesDirs(config: Config, currentPath: string)
4040
const subCandidates = await fs.readdir(candidatePath);
4141
invariant(
4242
subCandidates.length === 1,
43-
`There should only be one folder in a package cache (got ${subCandidates.join(',')})`,
43+
`There should only be one folder in a package cache (got ${subCandidates.join(',')} in ${candidatePath})`,
4444
);
4545

4646
for (const subCandidate of subCandidates) {

0 commit comments

Comments
 (0)