Skip to content

Commit

Permalink
Improve error message when path relativization fails #68
Browse files Browse the repository at this point in the history
  • Loading branch information
blutorange committed Sep 1, 2024
1 parent 975ed0a commit 6db54de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ See also the [closure compiler changelog](https://github.com/google/closure-comp
## 2.31.0

* Update to closure compiler `v20240317`
* Improve error message when path relativization fails #68

## 2.30.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ private FileHelper() {
* @return The path of the given {@code target}, relative to the specified {@code base} file.
*/
public static String relativizePath(File base, File target) throws IOException {
final Path targetPath = Paths.get(target.getCanonicalPath());
if (base == null) {
return targetPath.toString();
try {
final var targetPath = Paths.get(target.getCanonicalPath());
if (base == null) {
return targetPath.toString();
} else {
final var basePath = base.getCanonicalFile().toPath();
final var relativePath = basePath.relativize(targetPath).toString();
return relativePath;
}
}
else {
final Path basePath = base.getCanonicalFile().toPath();
final String relativePath = basePath.relativize(targetPath).toString();
return relativePath;
catch (final IOException e) {
throw new IOException("Failed to relativize path <" + target + "> against base directory <" + base +">");
}
}

Expand Down

0 comments on commit 6db54de

Please sign in to comment.