nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: peak/s5cmd
Pull request #291 (2021-05-19 10:24:57)

command/cp: fix minor printing issue if 'cp' command is called without arguments
#### before
```sh
$ s5cmd cp
ERROR "cp ": expected source and destination arguments
```

#### after
```sh
$ s5cmd cp
ERROR "cp": expected source and destination arguments
```


Patch:
diff --git a/command/cp.go b/command/cp.go
index d1e0b34..6a6f00d 100644
--- a/command/cp.go
+++ b/command/cp.go
@@ -758,5 +758,10 @@ func guessContentType(file *os.File) string {
 }
 
 func givenCommand(c *cli.Context) string {
-	return fmt.Sprintf("%v %v", c.Command.FullName(), strings.Join(c.Args().Slice(), " "))
+	cmd := c.Command.FullName()
+	if c.Args().Len() > 0 {
+		cmd = fmt.Sprintf("%v %v", cmd, strings.Join(c.Args().Slice(), " "))
+	}
+
+	return cmd
 }


Test patch:
diff --git a/e2e/app_test.go b/e2e/app_test.go
index 152cf4e..39fc919 100644
--- a/e2e/app_test.go
+++ b/e2e/app_test.go
@@ -22,7 +22,7 @@ func TestAppRetryCount(t *testing.T) {
 		{
 			name:             "retry_count_negative",
 			retry:            -1,
-			expectedError:    fmt.Errorf(`ERROR " ": retry count cannot be a negative value`),
+			expectedError:    fmt.Errorf(`ERROR retry count cannot be a negative value`),
 			expectedExitCode: 1,
 		},
 		{
Repository: peak/s5cmd
Pull request #351 (2021-09-09 11:35:29)

command/run: handle errors returned from parallel.Manager
Run command ignores errors returned from `parallel.Manager`. I think it should be resolved in v2.0.0. Related to https://github.com/peak/s5cmd/issues/304

igungor: I'm going to take care of this PR since Onur is not available for a month.
igungor: @aykutfarsak @ilkinulas PTAL

Patch:
diff --git a/command/run.go b/command/run.go
index e5fb247..f696b34 100644
--- a/command/run.go
+++ b/command/run.go
@@ -9,6 +9,7 @@ import (
 	"os"
 	"strings"
 
+	"github.com/hashicorp/go-multierror"
 	"github.com/kballard/go-shellquote"
 	"github.com/urfave/cli/v2"
 
@@ -63,12 +64,11 @@ func NewRunCommand() *cli.Command {
 			waiter := parallel.NewWaiter()
 
 			var errDoneCh = make(chan bool)
+			var merrorWaiter error
 			go func() {
 				defer close(errDoneCh)
-				for range waiter.Err() {
-					// app.ExitErrHandler is called after each command.Run
-					// invocation. Ignore the errors returned from parallel.Run,
-					// just drain the channel for synchronization.
+				for err := range waiter.Err() {
+					merrorWaiter = multierror.Append(merrorWaiter, err)
 				}
 			}()
 
@@ -130,7 +130,7 @@ func NewRunCommand() *cli.Command {
 			waiter.Wait()
 			<-errDoneCh
 
-			return scanner.Err()
+			return multierror.Append(merrorWaiter, scanner.Err()).ErrorOrNil()
 		},
 	}
 }


Test patch:
diff --git a/e2e/run_test.go b/e2e/run_test.go
index 49e753c..5a84cab 100644
--- a/e2e/run_test.go
+++ b/e2e/run_test.go
@@ -62,7 +62,7 @@ func TestRunFromStdinWithErrors(t *testing.T) {
 	cmd := s5cmd("run")
 	result := icmd.RunCmd(cmd, icmd.WithStdin(input))
 
-	result.Assert(t, icmd.Success)
+	result.Assert(t, icmd.Expected{ExitCode: 1})
 
 	assertLines(t, result.Stdout(), map[int]compareFunc{})
Repository: peak/s5cmd
Pull request #410 (2022-02-21 18:32:22)

command/run: print error if `run` argument doesn't exist
Before:
```
$ ./s5cmd run cmd.tx
$ echo $?
1
```

After:
```
$ ./s5cmd run cmd.tx
ERROR "run cmd.tx": open cmd.tx: no such file or directory
$ echo $?
1
```



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd0055b..2fab6f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
 #### Bugfixes
 - Fixed a bug about precedence of region detection, which auto region detection would always override region defined in environment or profile. ([#325](https://github.com/peak/s5cmd/issues/325))
 - Fixed a bug where errors did not result a non-zero exit code. ([#304](https://github.com/peak/s5cmd/issues/304))
+- Print error if the commands file of `run` command is not accessible. ([#410](https://github.com/peak/s5cmd/pull/410))
 
 ## v1.4.0 - 21 Sep 2021
 
diff --git a/command/run.go b/command/run.go
index d852a63..a54f6c6 100644
--- a/command/run.go
+++ b/command/run.go
@@ -51,6 +51,7 @@ func NewRunCommand() *cli.Command {
 			if c.Args().Len() == 1 {
 				f, err := os.Open(c.Args().First())
 				if err != nil {
+					printError(givenCommand(c), c.Command.Name, err)
 					return err
 				}
 				defer f.Close()


Test patch:
diff --git a/e2e/run_test.go b/e2e/run_test.go
index 5a84cab..94d3f2b 100644
--- a/e2e/run_test.go
+++ b/e2e/run_test.go
@@ -169,6 +169,24 @@ func TestRunFromFileJSON(t *testing.T) {
 	assertLines(t, result.Stderr(), map[int]compareFunc{})
 }
 
+func TestRunFromFileThatDoesntExist(t *testing.T) {
+	t.Parallel()
+
+	_, s5cmd, cleanup := setup(t)
+	defer cleanup()
+
+	cmd := s5cmd("run", "non-existent-file")
+	result := icmd.RunCmd(cmd)
+
+	result.Assert(t, icmd.Expected{ExitCode: 1})
+
+	assertLines(t, result.Stdout(), map[int]compareFunc{})
+
+	assertLines(t, result.Stderr(), map[int]compareFunc{
+		0: contains(`ERROR "run non-existent-file": open non-existent-file:`),
+	})
+}
+
 func TestRunWildcardCountGreaterEqualThanWorkerCount(t *testing.T) {
 	t.Parallel()
Repository: peak/s5cmd
Pull request #509 (2022-09-09 11:07:18)

log, parallel: fix help flag panicking
after #495, `s5cmd --help` started to panic:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x158798e]

goroutine 1 [running]:
github.com/peak/s5cmd/parallel.(*Manager).Close(...)
        /Users/boraberke/Documents/s5cmd/parallel/parallel.go:65
github.com/peak/s5cmd/parallel.Close(...)
        /Users/boraberke/Documents/s5cmd/parallel/global.go:16
github.com/peak/s5cmd/command.glob..func5(0x16af2c0?)
        /Users/boraberke/Documents/s5cmd/command/app.go:177 +0x10e
github.com/urfave/cli/v2.(*App).RunContext.func1()
        /Users/boraberke/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:309 +0x35
github.com/urfave/cli/v2.(*App).RunContext(0x1bf3c20, {0x1857a30?, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberke/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:321 +0xa5b
github.com/peak/s5cmd/command.Main({0x1857a30, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberke/Documents/s5cmd/command/app.go:235 +0xa6
main.main()
        /Users/boraberke/Documents/s5cmd/main.go:23 +0x9b
```

This is caused by [this commit](https://github.com/urfave/cli/commit/a1c26d5491ccae4a23f39c263445907256154793) from urfave/cli. `app.After` is deferred before `showAppHelp` is called. Fix this bug by making nil checks in log.go and parallel.go


Patch:
diff --git a/log/log.go b/log/log.go
index 3d03763..5ec149a 100644
--- a/log/log.go
+++ b/log/log.go
@@ -50,8 +50,10 @@ func Error(msg Message) {
 
 // Close closes logger and its channel.
 func Close() {
-	close(outputCh)
-	<-global.donech
+	if global != nil {
+		close(outputCh)
+		<-global.donech
+	}
 }
 
 // Logger is a structure for logging messages.
diff --git a/parallel/global.go b/parallel/global.go
index a0b2e9a..843d4b2 100644
--- a/parallel/global.go
+++ b/parallel/global.go
@@ -13,7 +13,11 @@ func Init(workercount int) {
 
 // Close waits all jobs to finish and
 // closes the semaphore of global ParallelManager.
-func Close() { global.Close() }
+func Close() {
+	if global != nil {
+		global.Close()
+	}
+}
 
 // Run runs global ParallelManager.
 func Run(task Task, waiter *Waiter) { global.Run(task, waiter) }


Test patch:
diff --git a/e2e/app_test.go b/e2e/app_test.go
index e86cd9d..b24646f 100644
--- a/e2e/app_test.go
+++ b/e2e/app_test.go
@@ -7,6 +7,8 @@ import (
 	"strings"
 	"testing"
 
+	"github.com/peak/s5cmd/command"
+
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/icmd"
 )
@@ -188,6 +190,26 @@ func TestAppUnknownCommand(t *testing.T) {
 	})
 }
 
+func TestAppHelp(t *testing.T) {
+	t.Parallel()
+
+	_, s5cmd := setup(t)
+
+	// without any specific command
+	cmd := s5cmd("--help")
+	result := icmd.RunCmd(cmd)
+
+	result.Assert(t, icmd.Success)
+
+	// with commands
+	for _, command := range command.Commands() {
+		cmd := s5cmd(command.Name, "--help")
+		result = icmd.RunCmd(cmd)
+
+		result.Assert(t, icmd.Success)
+	}
+}
+
 func TestUsageError(t *testing.T) {
 	t.Parallel()