Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2022-02-11 04:48:49 +0300
committerJames Fargher <proglottis@gmail.com>2022-02-22 00:25:50 +0300
commit83b2e667cc4ad5c34b1da82a4c96e0d0e76a39c1 (patch)
tree0517d942a014579d3b77b311a1edff8b41ed7f9d
parent823af13768eb697d85abe0ca763d18d4ef43c544 (diff)
gitaly-git2go: Send all errors over gob
Previously stderr was used to send plaintext errors back to the caller. Since we are looking to use stderr for logging, we need to stop sending errors this way. Here we use the universal gob response error field instead. Client side must continue reading errors from both gob and stderr for a release so that we can safely upgrade.
-rw-r--r--cmd/gitaly-git2go/main.go35
1 files changed, 21 insertions, 14 deletions
diff --git a/cmd/gitaly-git2go/main.go b/cmd/gitaly-git2go/main.go
index 67152d42b..1bbdf6e20 100644
--- a/cmd/gitaly-git2go/main.go
+++ b/cmd/gitaly-git2go/main.go
@@ -31,44 +31,51 @@ var subcommands = map[string]subcmd{
"submodule": &submoduleSubcommand{},
}
-func fatalf(format string, args ...interface{}) {
- fmt.Fprintf(os.Stderr, format+"\n", args...)
- os.Exit(1)
+func fatalf(encoder *gob.Encoder, format string, args ...interface{}) {
+ // Once logging has been implemented these encoding errors can be logged.
+ // Until then these will be ignored as we can no longer use stderr.
+ // https://gitlab.com/gitlab-org/gitaly/-/issues/3229
+ _ = encoder.Encode(git2go.Result{
+ Err: git2go.SerializableError(fmt.Errorf(format, args...)),
+ })
+ // An exit code of 1 would indicate an error over stderr. Since our errors
+ // are encoded over gob, we need to exit cleanly
+ os.Exit(0)
}
func main() {
- flags := flag.NewFlagSet(git2go.BinaryName, flag.ExitOnError)
+ decoder := gob.NewDecoder(os.Stdin)
+ encoder := gob.NewEncoder(os.Stdout)
+
+ flags := flag.NewFlagSet(git2go.BinaryName, flag.ContinueOnError)
if err := flags.Parse(os.Args); err != nil {
- fatalf("parsing flags: %s", err)
+ fatalf(encoder, "parsing flags: %s", err)
}
if flags.NArg() < 2 {
- fatalf("missing subcommand")
+ fatalf(encoder, "missing subcommand")
}
- decoder := gob.NewDecoder(os.Stdin)
- encoder := gob.NewEncoder(os.Stdout)
-
subcmd, ok := subcommands[flags.Arg(1)]
if !ok {
- fatalf("unknown subcommand: %q", flags.Arg(1))
+ fatalf(encoder, "unknown subcommand: %q", flags.Arg(0))
}
subcmdFlags := subcmd.Flags()
if err := subcmdFlags.Parse(flags.Args()[2:]); err != nil {
- fatalf("parsing flags of %q: %s", subcmdFlags.Name(), err)
+ fatalf(encoder, "parsing flags of %q: %s", subcmdFlags.Name(), err)
}
if subcmdFlags.NArg() != 0 {
- fatalf("%s: trailing arguments", subcmdFlags.Name())
+ fatalf(encoder, "%s: trailing arguments", subcmdFlags.Name())
}
if err := git.EnableFsyncGitDir(true); err != nil {
- fatalf("enable fsync: %s", err)
+ fatalf(encoder, "enable fsync: %s", err)
}
if err := subcmd.Run(context.Background(), decoder, encoder); err != nil {
- fatalf("%s: %s", subcmdFlags.Name(), err)
+ fatalf(encoder, "%s: %s", subcmdFlags.Name(), err)
}
}