Skip to content

Commit

Permalink
fix(log): Adding path in the error message
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Aug 30, 2023
1 parent 289abfc commit e3fa6b4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
20 changes: 12 additions & 8 deletions pkg/crud/upload_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,23 @@ func (s Service) mergeChunk(w http.ResponseWriter, r *http.Request, request prov
s.error(w, r, request, model.WrapInternal(err))
return
}

filePath := request.SubPath(fileName)
err = provider.WriteToStorage(ctx, s.storage, filePath, size, file)

if err == nil {
go func(ctx context.Context) {
if info, infoErr := s.storage.Stat(ctx, filePath); infoErr != nil {
slog.Error("get info for upload event", "err", infoErr)
} else {
s.pushEvent(ctx, provider.NewUploadEvent(ctx, request, info, s.bestSharePath(filePath), s.renderer))
}
}(cntxt.WithoutDeadline(ctx))
if err != nil {
s.error(w, r, request, model.WrapInternal(err))
return
}

go func(ctx context.Context) {
if info, infoErr := s.storage.Stat(ctx, filePath); infoErr != nil {
slog.Error("get info for upload event", "err", infoErr)
} else {
s.pushEvent(ctx, provider.NewUploadEvent(ctx, request, info, s.bestSharePath(filePath), s.renderer))
}
}(cntxt.WithoutDeadline(ctx))

if err = os.RemoveAll(tempFolder); err != nil {
slog.Error("delete chunk folder", "err", err, "folder", tempFolder)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/metadata/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s Service) saveMetadata(ctx context.Context, item absto.Item, data any) er
}

if err = s.storage.Mkdir(ctx, dirname, absto.DirectoryPerm); err != nil {
return fmt.Errorf("create directory: %w", err)
return fmt.Errorf("create directory `%s`: %w", dirname, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func WriteToStorage(ctx context.Context, storageService absto.Storage, output st
directory := path.Dir(output)

if err = storageService.Mkdir(ctx, directory, absto.DirectoryPerm); err != nil {
return fmt.Errorf("create directory: %w", err)
return fmt.Errorf("create directory `%s`: %w", directory, err)
}

err = storageService.WriteTo(ctx, output, reader, absto.WriteOpts{Size: size})
Expand Down
6 changes: 3 additions & 3 deletions pkg/search/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ func (s Service) save(ctx context.Context, item absto.Item, content Searches) er

if _, err := s.storage.Stat(ctx, dirname); err != nil {
if !absto.IsNotExist(err) {
return fmt.Errorf("check directory existence: %w", err)
return fmt.Errorf("check directory `%s` existence: %w", dirname, err)
}

if err = s.storage.Mkdir(ctx, dirname, absto.DirectoryPerm); err != nil {
return fmt.Errorf("create directory: %w", err)
return fmt.Errorf("create directory `%s`: %w", dirname, err)
}
}

if err := provider.SaveJSON(ctx, s.storage, filename, content); err != nil {
return fmt.Errorf("save: %w", err)
return fmt.Errorf("save `%s`: %w", filename, err)
}

return nil
Expand Down

0 comments on commit e3fa6b4

Please sign in to comment.