Skip to content

FileSystem.NewWriter not returning explicit error if file Creation Failed #3146

@akshat-kumar-singhal

Description

@akshat-kumar-singhal

Describe the bug
In case the file creation fails, NewWriter returns an object implementing io.WriteCloser instead of explicit error, misleading the user that the file creation succeeded.

        f, err := os.Create(name)
	if err != nil {
		return &failWriter{err: err}
	}

To Reproduce
Try to create a file in directory without write permission to the running user.

Expected behavior
Ideally NewWriter should return an explicit error. However, that would be a breaking change.
As a workaround, we could type check the response from NewWriter and if it matches failWriter, we return an error instead of considering it as success case in the following methods:

  • func (c *CommonFileSystem) Mkdir(name string, _ os.FileMode) error
  • func (c *CommonFileSystem) Create(name string) (File, error)
  • func (c *CommonFileSystem) handleWriteFlags(name string, flag int) (File, error)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions