Skip to content

Commit

Permalink
Make the string form of "invisible" RepositoryNames stand out
Browse files Browse the repository at this point in the history
These invalid RepositoryName objects often are often hidden in labels, which means that a label with an invalid RepositoryName could have a perfectly normal looking string form like "@foo//bar". With this change, it would look like "@[unknown repo 'foo' requested from @mod~1.0]//bar", making it immediately stand out and saving debugging time.

PiperOrigin-RevId: 470961893
Change-Id: Ie48d788660aca76cb8a5e4f5138d9caad51b08ee
  • Loading branch information
Wyverald authored and copybara-github committed Aug 30, 2022
1 parent 535f9d7 commit a71ebc1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,17 @@ public RepositoryName getOwnerRepoIfNotVisible() {
return ownerRepoIfNotVisible;
}

/** Returns if this is the main repository, that is, {@link #getName} is empty. */
/** Returns if this is the main repository. */
public boolean isMain() {
return name.isEmpty();
return equals(MAIN);
}

/** Returns the repository name, with leading "{@literal @}". */
public String getNameWithAt() {
if (!isVisible()) {
return String.format(
"@[unknown repo '%s' requested from %s]", name, ownerRepoIfNotVisible.getNameWithAt());
}
return '@' + name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ public TargetPattern parse(String pattern) throws TargetParsingException {
if (!repository.isVisible()) {
throw new TargetParsingException(
String.format(
"Repository '%s' is not visible from repository '@%s'",
repository.getNameWithAt(), repository.getOwnerRepoIfNotVisible()),
"Repository '@%s' is not visible from repository '@%s'",
repository.getName(), repository.getOwnerRepoIfNotVisible()),
Code.PACKAGE_NOT_FOUND);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
if (!repositoryName.isVisible()) {
return new NoRepositoryDirectoryValue(
String.format(
"Repository '%s' is not visible from repository '%s'",
repositoryName.getNameWithAt(),
repositoryName.getOwnerRepoIfNotVisible().getNameWithAt()));
"Repository '@%s' is not visible from repository '%s'",
repositoryName.getName(), repositoryName.getOwnerRepoIfNotVisible().getNameWithAt()));
}

Map<RepositoryName, PathFragment> overrides = REPOSITORY_OVERRIDES.get(env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public SkyValue compute(SkyKey skyKey, Environment env)
return new PackageLookupValue.NoRepositoryPackageLookupValue(
repoName.getNameWithAt(),
String.format(
"Repository '%s' is not visible from repository '%s'",
repoName.getNameWithAt(), repoName.getOwnerRepoIfNotVisible().getNameWithAt()));
"Repository '@%s' is not visible from repository '%s'",
repoName.getName(), repoName.getOwnerRepoIfNotVisible().getNameWithAt()));
}

if (deletedPackages.get().contains(packageKey)) {
Expand Down

0 comments on commit a71ebc1

Please sign in to comment.