Structured errors for GetTreeEntries
Gitaly 16.1 protocol gets structured errors in CommitService.GetTreeEntries
. Implementation appears in Gitaly 16.3, behind the GetTreeEntriesStructuredErrors
feature flag.
$ PAGER= git diff 1ed139ab2d95e27491b49fcced61d0dc99834ab2..c68746b159bc3c4fb0e84331a002b1304dd24889 -- proto/{commit,errors}.proto
diff --git a/proto/commit.proto b/proto/commit.proto
index d2c4353a1..780b7cc2d 100644
--- a/proto/commit.proto
+++ b/proto/commit.proto
@@ -2,6 +2,7 @@ syntax = "proto3";
package gitaly;
+import "errors.proto";
import "google/protobuf/timestamp.proto";
import "lint.proto";
import "shared.proto";
@@ -467,6 +468,17 @@ message GetTreeEntriesResponse {
PaginationCursor pagination_cursor = 2;
}
+// GetTreeEntriesError may be returned when GetTreeEntries fails with a specific root
+// cause.
+message GetTreeEntriesError {
+ oneof error {
+ // ResolveTree is set when the provided revision ID could not be resolved.
+ ResolveRevisionError resolve_tree = 1;
+ // Path is set when the provided path is not valid.
+ PathError path = 2;
+ }
+}
+
// This comment is left unintentionally blank.
message ListFilesRequest {
// This comment is left unintentionally blank.
diff --git a/proto/errors.proto b/proto/errors.proto
index dbd3b3be5..c383eadff 100644
--- a/proto/errors.proto
+++ b/proto/errors.proto
@@ -161,3 +161,29 @@ message CustomHookError {
// HookType is the type of the hook.
HookType hook_type = 3;
}
+
+// PathError is an error returned when there is an issue with the path provided.
+message PathError {
+ // ErrorType is the type of error encountered.
+ enum ErrorType {
+ // PathError_ERROR_TYPE_UNSPECIFIED is the default error type and should never be set.
+ ERROR_TYPE_UNSPECIFIED = 0;
+ // PathError_ERROR_TYPE_EMPTY_PATH is the error type when the provided path is empty.
+ ERROR_TYPE_EMPTY_PATH = 1;
+ // PathError_ERROR_TYPE_RELATIVE_PATH_ESCAPES_REPOSITORY is the error type when there are
+ // traversing components found in the path and it either escapes the repository or is not
+ // supported by the RPC.
+ ERROR_TYPE_RELATIVE_PATH_ESCAPES_REPOSITORY = 2;
+ // PathError_ERROR_TYPE_ABSOLUTE_PATH is the error type when an absolute path is provided
+ // while a relative path was expected.
+ ERROR_TYPE_ABSOLUTE_PATH = 3;
+ // PathError_ERROR_TYPE_LONG_PATH is the error type when the path is too long.
+ ERROR_TYPE_LONG_PATH = 4;
+ };
+
+ // Path is the file or directory path that triggered the error. The path may be
+ // truncated due to size limits.
+ bytes path = 1;
+ // ErrorType is the type of path error that occurred.
+ ErrorType error_type = 2;
+}
Feature flag introduction, on the Gitaly side:
$ git diff v16.2.0..v16.3.0 | grep -E 'GetTreeEntries.*NewFeatureFlag'
+var GetTreeEntriesStructuredErrors = NewFeatureFlag(
and on the Rails side, the corresponding feature flag seems to appear in GitLab v16.4
We should do it earlier (as of Heptapod 0.40.0), because the automated upstream merge process will not detect the Rails feature flag introduction.
This method is implemented in RHGitaly, and this will be the first implementation of structured errors in Rust, which probably will entail some infrastructure works.
Edited by Georges Racinet