Skip to content

fix(file): return explicit error from StorageProvider.NewWriter#3175

Open
coolwednesday wants to merge 1 commit intodevelopmentfrom
fix/newwriter-explicit-error
Open

fix(file): return explicit error from StorageProvider.NewWriter#3175
coolwednesday wants to merge 1 commit intodevelopmentfrom
fix/newwriter-explicit-error

Conversation

@coolwednesday
Copy link
Member

@coolwednesday coolwednesday commented Mar 17, 2026

Summary

  • Closes FileSystem.NewWriter not returning explicit error if file Creation Failed #3146
  • Changed StorageProvider.NewWriter and MetadataWriter.NewWriterWithOptions to return (io.WriteCloser, error) instead of just io.WriteCloser
  • Removed the failWriter pattern across all providers (local, GCS, Azure, FTP) that silently deferred errors to Write/Close time
  • Updated all callers in CommonFileSystem (Create, Mkdir, handleWriteFlags, CreateWithOptions) to handle the explicit error

Why

The previous failWriter approach masked initialization errors — callers only discovered problems when they tried to Write() or Close(), making debugging harder. Returning the error explicitly at creation time is the idiomatic Go pattern.

Impact

This is not a breaking change for end users. StorageProvider and MetadataWriter are internal interfaces not exposed in the public API. Users interact with higher-level FileSystem/FileSystemProvider methods whose signatures are unchanged.

Test plan

  • All pkg/gofr/datasource/file tests pass
  • All pkg/gofr/datasource/file/azure tests pass
  • All pkg/gofr/datasource/file/ftp tests pass
  • All pkg/gofr/datasource/file/gcs tests pass
  • Linter passes on all four packages

Change StorageProvider.NewWriter and MetadataWriter.NewWriterWithOptions
to return (io.WriteCloser, error) instead of just io.WriteCloser. This
removes the failWriter pattern that silently deferred errors to Write/Close
time, making error handling explicit at the point of writer creation.

Fixes #3146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSystem.NewWriter not returning explicit error if file Creation Failed

1 participant