pubsub
created pr with
20.1
cmds
checkout latest patchset:
ssh pr.pico.sh print 20 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 20.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 20
Patchset
20.1
refactor(sftp): print errors from server to client
Eric Bower
2024-08-20T03:16:02ZMost clients do not print the error from request server so we need to do it ourselves. reference: https://github.com/pkg/sftp/issues/219#issuecomment-358136231
Semantic diff summary
5 added,
3 modified,
0 signature changed,
0 removed
across 2 analyzed files
+34
-0
send/sftp/handler.go
#
| ... | ... | @@ -127,3 +128,36 @@ func (f *handler) Fileread(r *sftp.Request) (io.ReaderAt, error) { | |
| 127 | 128 | ||
| 128 | 129 | return reader, err | |
| 129 | 130 | } | |
| 131 | + | ||
| 132 | + | type handlererr struct { | |
| 133 | + | Handler *handler | |
| 134 | + | } | |
| 135 | + | ||
| 136 | + | func (f *handlererr) Filecmd(r *sftp.Request) error { | |
| 137 | + | err := f.Handler.Filecmd(r) | |
| 138 | + | if err != nil { | |
| 139 | + | wish.Errorln(f.Handler.session, err) | |
| 140 | + | } | |
| 141 | + | return err | |
| 142 | + | } | |
| 143 | + | func (f *handlererr) Filelist(r *sftp.Request) (sftp.ListerAt, error) { | |
| 144 | + | result, err := f.Handler.Filelist(r) | |
| 145 | + | if err != nil { | |
| 146 | + | wish.Errorln(f.Handler.session, err) | |
| 147 | + | } | |
| 148 | + | return result, err | |
| 149 | + | } | |
| 150 | + | func (f *handlererr) Filewrite(r *sftp.Request) (io.WriterAt, error) { | |
| 151 | + | result, err := f.Handler.Filewrite(r) | |
| 152 | + | if err != nil { | |
| 153 | + | wish.Errorln(f.Handler.session, err) | |
| 154 | + | } | |
| 155 | + | return result, err | |
| 156 | + | } | |
| 157 | + | func (f *handlererr) Fileread(r *sftp.Request) (io.ReaderAt, error) { | |
| 158 | + | result, err := f.Handler.Fileread(r) | |
| 159 | + | if err != nil { | |
| 160 | + | wish.Errorln(f.Handler.session, err) | |
| 161 | + | } | |
| 162 | + | return result, err | |
| 163 | + | } |
+9
-5
send/sftp/sftp.go
#
| ... | ... | @@ -25,19 +26,21 @@ func SubsystemHandler(writeHandler utils.CopyFromClientHandler) ssh.SubsystemHan | |
| 25 | 26 | defer func() { | |
| 26 | 27 | if r := recover(); r != nil { | |
| 27 | 28 | writeHandler.GetLogger().Error("error running sftp middleware", "err", r) | |
| 28 | - | _, _ = session.Stderr().Write([]byte("error running sftp middleware, check the flags you are using\r\n")) | |
| 29 | + | wish.Println(session, "error running sftp middleware, check the flags you are using") | |
| 29 | 30 | } | |
| 30 | 31 | }() | |
| 31 | 32 | ||
| 32 | 33 | err := writeHandler.Validate(session) | |
| 33 | 34 | if err != nil { | |
| 34 | - | utils.ErrorHandler(session, err) | |
| 35 | + | wish.Errorln(session, err) | |
| 35 | 36 | return | |
| 36 | 37 | } | |
| 37 | 38 | ||
| 38 | - | handler := &handler{ | |
| 39 | - | session: session, | |
| 40 | - | writeHandler: writeHandler, | |
| 39 | + | handler := &handlererr{ | |
| 40 | + | Handler: &handler{ | |
| 41 | + | session: session, | |
| 42 | + | writeHandler: writeHandler, | |
| 43 | + | }, | |
| 41 | 44 | } | |
| 42 | 45 | ||
| 43 | 46 | handlers := sftp.Handlers{ |
| ... | ... | @@ -51,6 +54,7 @@ func SubsystemHandler(writeHandler utils.CopyFromClientHandler) ssh.SubsystemHan | |
| 51 | 54 | ||
| 52 | 55 | err = requestServer.Serve() | |
| 53 | 56 | if err != nil && !errors.Is(err, io.EOF) { | |
| 57 | + | wish.Errorln(session, err) | |
| 54 | 58 | writeHandler.GetLogger().Error("Error serving sftp subsystem", "err", err) | |
| 55 | 59 | } | |
| 56 | 60 | } |