Improve error message if CodeOwnerSubmitRule fails due non-UTF8 path

It's a known issue that the code-owners plugin fails for paths that
contain unicode characters if the system language setting defines an
encoding that doesn't support unicode characters. If this happens
during submit the error message didn't tell the user which path was bad.
Fix this.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I722f838c4e115811fe67aacfb6430f6e8b6125d1
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSubmitRule.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSubmitRule.java
index 4c23676..21f411c 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSubmitRule.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSubmitRule.java
@@ -34,6 +34,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import java.io.IOException;
+import java.nio.file.InvalidPathException;
 import java.util.Optional;
 
 /** Submit rule that checks that all files in a change have been approved by their code owners. */
@@ -99,6 +100,11 @@
                 " for patch set %d of change %d",
                 changeData.currentPatchSet().id().get(), changeData.change().getId().get());
       }
+      Optional<InvalidPathException> invalidPathException =
+          CodeOwnersExceptionHook.getInvalidPathException(t);
+      if (invalidPathException.isPresent()) {
+        errorMessage += String.format(" (cause: %s)", invalidPathException.get().getMessage());
+      }
       errorMessage += ".";
       logger.atSevere().withCause(t).log(errorMessage);
       return Optional.of(ruleError(errorMessage));
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersExceptionHook.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersExceptionHook.java
index 8a2e85e..9f07ea2 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersExceptionHook.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersExceptionHook.java
@@ -89,7 +89,7 @@
     return getInvalidPathException(throwable).isPresent();
   }
 
-  private static Optional<InvalidPathException> getInvalidPathException(Throwable throwable) {
+  public static Optional<InvalidPathException> getInvalidPathException(Throwable throwable) {
     return getInvalidPluginConfigurationCause(InvalidPathException.class, throwable);
   }