cmd/s3-benchmark: add exit error information (#402)

This commit is contained in:
Egon Elbre 2018-10-01 14:28:45 +03:00 committed by GitHub
parent 39b3a09456
commit 0076b17c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
@ -50,7 +51,7 @@ func (client *AWSCLI) MakeBucket(bucket, location string) error {
cmd := client.cmd("s3", "mb", "s3://"+bucket, "--region", location)
_, err := cmd.Output()
if err != nil {
return AWSCLIError.Wrap(err)
return AWSCLIError.Wrap(fullExitError(err))
}
return nil
}
@ -60,7 +61,7 @@ func (client *AWSCLI) RemoveBucket(bucket string) error {
cmd := client.cmd("s3", "rb", "s3://"+bucket)
_, err := cmd.Output()
if err != nil {
return AWSCLIError.Wrap(err)
return AWSCLIError.Wrap(fullExitError(err))
}
return nil
}
@ -70,7 +71,7 @@ func (client *AWSCLI) ListBuckets() ([]string, error) {
cmd := client.cmd("s3api", "list-buckets", "--output", "json")
jsondata, err := cmd.Output()
if err != nil {
return nil, AWSCLIError.Wrap(err)
return nil, AWSCLIError.Wrap(fullExitError(err))
}
var response struct {
@ -81,7 +82,7 @@ func (client *AWSCLI) ListBuckets() ([]string, error) {
err = json.Unmarshal(jsondata, &response)
if err != nil {
return nil, AWSCLIError.Wrap(err)
return nil, AWSCLIError.Wrap(fullExitError(err))
}
names := []string{}
@ -99,7 +100,7 @@ func (client *AWSCLI) Upload(bucket, objectName string, data []byte) error {
cmd.Stdin = bytes.NewReader(data)
_, err := cmd.Output()
if err != nil {
return AWSCLIError.Wrap(err)
return AWSCLIError.Wrap(fullExitError(err))
}
return nil
}
@ -111,7 +112,7 @@ func (client *AWSCLI) UploadMultipart(bucket, objectName string, data []byte, th
cmd.Stdin = bytes.NewReader(data)
_, err := cmd.Output()
if err != nil {
return AWSCLIError.Wrap(err)
return AWSCLIError.Wrap(fullExitError(err))
}
return nil
}
@ -126,7 +127,7 @@ func (client *AWSCLI) Download(bucket, objectName string, buffer []byte) ([]byte
err := cmd.Run()
if err != nil {
return nil, AWSCLIError.Wrap(err)
return nil, AWSCLIError.Wrap(fullExitError(err))
}
return buf.data, nil
@ -146,7 +147,7 @@ func (client *AWSCLI) Delete(bucket, objectName string) error {
cmd := client.cmd("s3", "rm", "s3://"+bucket+"/"+objectName)
_, err := cmd.Output()
if err != nil {
return AWSCLIError.Wrap(err)
return AWSCLIError.Wrap(fullExitError(err))
}
return nil
}
@ -160,7 +161,7 @@ func (client *AWSCLI) ListObjects(bucket, prefix string) ([]string, error) {
jsondata, err := cmd.Output()
if err != nil {
return nil, AWSCLIError.Wrap(err)
return nil, AWSCLIError.Wrap(fullExitError(err))
}
var response struct {
@ -171,7 +172,7 @@ func (client *AWSCLI) ListObjects(bucket, prefix string) ([]string, error) {
err = json.Unmarshal(jsondata, &response)
if err != nil {
return nil, AWSCLIError.Wrap(err)
return nil, AWSCLIError.Wrap(fullExitError(err))
}
names := []string{}
@ -181,3 +182,14 @@ func (client *AWSCLI) ListObjects(bucket, prefix string) ([]string, error) {
return names, nil
}
// fullExitError returns error string with the Stderr output
func fullExitError(err error) error {
if err == nil {
return nil
}
if exitErr, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("%v\n%v", exitErr.Error(), string(exitErr.Stderr))
}
return err
}