Skip to content

Commit

Permalink
Added error wrapping to more funcs in ftp
Browse files Browse the repository at this point in the history
  • Loading branch information
funkyshu committed Aug 31, 2024
1 parent 614e819 commit 288580c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions backend/ftp/dataconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,23 @@ func getDataConn(ctx context.Context, authority utils.Authority, fs *FileSystem,
if fs.dataconn != nil && fs.dataconn.Mode() != t {
// wrong session type ... close current session and unset it (ps so we can set a new one after)
if err := fs.dataconn.Close(); err != nil {
return nil, wrapGetDataConnError(err)
return nil, wrapGetDataConnError(fmt.Errorf("dataconn.Close error: %w", err))
}
fs.dataconn = nil
}

if fs.dataconn == nil || fs.resetConn {
client, err := fs.Client(ctx, authority)
if err != nil {
return nil, wrapGetDataConnError(err)
return nil, wrapGetDataConnError(fmt.Errorf("fs.Client error: %w", err))
}

switch t {
case types.OpenRead:
resp, err := client.RetrFrom(f.Path(), uint64(f.offset))
// check errors
if err != nil {
return nil, wrapGetDataConnError(err)
return nil, wrapGetDataConnError(fmt.Errorf("client.RetrFrom error: %w", err))
}
fs.dataconn = &dataConn{
R: resp,
Expand Down
2 changes: 1 addition & 1 deletion backend/ftp/fileSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (fs *FileSystem) Client(ctx context.Context, authority utils.Authority) (ty
var err error
fs.ftpclient, err = defaultClientGetter(ctx, authority, opts)
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot get client: %w", err)
}
} else {
return nil, fmt.Errorf("unable to create client, vfs.Options must be an ftp.Options")
Expand Down
4 changes: 2 additions & 2 deletions backend/ftp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func getClient(ctx context.Context, authority utils.Authority, opts Options) (ty
// dial connection
c, err := _ftp.Dial(fetchHostPortString(authority), fetchDialOptions(ctx, authority, opts)...)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to dial connection: %w", err)
}

// login
err = c.Login(fetchUsername(authority), fetchPassword(opts))
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to login: %w", err)
}

return c, nil
Expand Down

0 comments on commit 288580c

Please sign in to comment.