From 6bb8c180b2c44911775cd045b8c90a916de738d9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 27 Apr 2024 15:55:30 +0200 Subject: [PATCH] Handle scanner error in RunAndProcessLines Scanners can return errors (e.g. ErrTooLong), and if we don't handle it, the cmd.Wait() call below will block forever because nobody drains the command's output. This happens for CommitLoader.GetCommits when there's a commit whose subject line is longer than approx. 65500 characters; in that case, lazygit would lock up completely. With this fix it remains usable, but the commit list is truncated before the bad commit, which is not good enough. We'll improve that in the remaining commits of this branch. --- pkg/commands/oscommands/cmd_obj_runner.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go index 296850e32..5f28196e3 100644 --- a/pkg/commands/oscommands/cmd_obj_runner.go +++ b/pkg/commands/oscommands/cmd_obj_runner.go @@ -178,6 +178,11 @@ func (self *cmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line st } } + if scanner.Err() != nil { + _ = Kill(cmd) + return scanner.Err() + } + _ = cmd.Wait() self.log.Infof("%s (%s)", cmdObj.ToString(), time.Since(t))