Skip to content

Commit 068cbbb

Browse files
committed
chore: Fix minor code smells
1 parent c38c091 commit 068cbbb

File tree

7 files changed

+17
-6
lines changed

7 files changed

+17
-6
lines changed

cmd/tusd/cli/composer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func CreateComposer() {
125125

126126
azService, err := azurestore.NewAzureService(azConfig)
127127
if err != nil {
128-
stderr.Fatalf(err.Error())
128+
stderr.Fatalf("Unable to create Azure BlockBlob Storage service: %s", err)
129129
}
130130

131131
store := azurestore.New(azService)

cmd/tusd/cli/flags.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ func ParseFlags() {
205205
f.DurationVar(&Flags.GracefulRequestCompletionTimeout, "request-completion-timeout", 10*time.Second, "Period after which all request operations are cancelled when the request is stopped by the client.")
206206
})
207207

208-
fs.Parse()
208+
if err := fs.Parse(); err != nil {
209+
stderr.Fatalf("Failed to parse flags: %s", err)
210+
}
209211

210212
SetEnabledHooks()
211213

pkg/handler/unrouted_handler.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,10 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
11031103
}
11041104

11051105
handler.sendResp(c, resp)
1106-
io.Copy(w, src)
1106+
if _, err := io.Copy(w, src); err != nil {
1107+
handler.sendError(c, err)
1108+
return
1109+
}
11071110

11081111
src.Close()
11091112
}

pkg/hooks/grpc/grpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (g *GrpcHook) Setup() error {
7979
}
8080
grpcOpts = append(grpcOpts, grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(opts...)))
8181

82-
conn, err := grpc.Dial(g.Endpoint, grpcOpts...)
82+
conn, err := grpc.NewClient(g.Endpoint, grpcOpts...)
8383
if err != nil {
8484
return err
8585
}

pkg/hooks/hooks_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func TestNewHandlerWithHooks(t *testing.T) {
180180
},
181181
},
182182
}, err)
183+
a.Equal(handler.HTTPResponse{}, resp_got)
183184

184185
// Successful post-* hooks
185186
uploadHandler.CreatedUploads <- event

pkg/s3store/s3store.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,9 @@ func (upload *s3Upload) concatUsingDownload(ctx context.Context, partialUploads
952952
}
953953

954954
// Seek to the beginning of the file, so the entire file is being uploaded
955-
file.Seek(0, 0)
955+
if _, err := file.Seek(0, 0); err != nil {
956+
return err
957+
}
956958

957959
// Upload the entire file to S3
958960
_, err = store.Service.PutObject(ctx, &s3.PutObjectInput{

pkg/s3store/s3store_part_producer.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ func (spp *s3PartProducer) nextPart(size int64) (fileChunk, bool, error) {
109109
spp.diskWriteDurationMetric.Observe(ms)
110110

111111
// Seek to the beginning of the file
112-
file.Seek(0, 0)
112+
if _, err := file.Seek(0, 0); err != nil {
113+
cleanUpTempFile(file)
114+
return fileChunk{}, false, err
115+
}
113116

114117
return fileChunk{
115118
reader: file,

0 commit comments

Comments
 (0)