-
-
Notifications
You must be signed in to change notification settings - Fork 2k
chore: Improve error messages in SaveFileToStorage #4173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
80e0203
485129f
23f1d53
240b1ad
d310941
3364650
3d08591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -519,7 +519,7 @@ func (*DefaultCtx) SaveFile(fileheader *multipart.FileHeader, path string) error | |
| func (c *DefaultCtx) SaveFileToStorage(fileheader *multipart.FileHeader, path string, storage Storage) error { | ||
| file, err := fileheader.Open() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open: %w", err) | ||
| return fmt.Errorf("failed to open file %s: %w", fileheader.Filename, err) | ||
|
||
| } | ||
| defer file.Close() //nolint:errcheck // not needed | ||
|
|
||
|
|
@@ -529,25 +529,25 @@ func (c *DefaultCtx) SaveFileToStorage(fileheader *multipart.FileHeader, path st | |
| } | ||
|
|
||
| if fileheader.Size > 0 && fileheader.Size > int64(maxUploadSize) { | ||
| return fmt.Errorf("failed to read: %w", fasthttp.ErrBodyTooLarge) | ||
| return fmt.Errorf("failed to read file %s: %w", fileheader.Filename, fasthttp.ErrBodyTooLarge) | ||
pratikramteke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| buf := bytebufferpool.Get() | ||
| defer bytebufferpool.Put(buf) | ||
|
|
||
| limitedReader := io.LimitReader(file, int64(maxUploadSize)+1) | ||
| if _, err = buf.ReadFrom(limitedReader); err != nil { | ||
| return fmt.Errorf("failed to read: %w", err) | ||
| return fmt.Errorf("failed to read file %s: %w", fileheader.Filename, err) | ||
pratikramteke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if buf.Len() > maxUploadSize { | ||
| return fmt.Errorf("failed to read: %w", fasthttp.ErrBodyTooLarge) | ||
| return fmt.Errorf("failed to read file %s: %w", fileheader.Filename, fasthttp.ErrBodyTooLarge) | ||
pratikramteke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| data := append([]byte(nil), buf.Bytes()...) | ||
|
|
||
| if err := storage.SetWithContext(c.Context(), path, data, 0); err != nil { | ||
| return fmt.Errorf("failed to store: %w", err) | ||
| return fmt.Errorf("failed to store file %s at %s: %w", fileheader.Filename, path, err) | ||
pratikramteke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.