Logs
Patchsets
Patchset ps-36
refactor(sftp): print errors from server to client
Eric Bower
send/sftp/handler.go
+34
-0
send/sftp/sftp.go
+9
-5
refactor(sftp): print errors from server to client
Most 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
send/sftp/handler.go
link
+34
-0
+34
-0
1diff --git a/send/sftp/handler.go b/send/sftp/handler.go
2index 9fc8e61..af0038b 100644
3--- a/send/sftp/handler.go
4+++ b/send/sftp/handler.go
5@@ -10,6 +10,7 @@ import (
6 "slices"
7
8 "github.com/charmbracelet/ssh"
9+ "github.com/charmbracelet/wish"
10 "github.com/picosh/send/send/utils"
11 "github.com/pkg/sftp"
12 )
13@@ -127,3 +128,36 @@ func (f *handler) Fileread(r *sftp.Request) (io.ReaderAt, error) {
14
15 return reader, err
16 }
17+
18+type handlererr struct {
19+ Handler *handler
20+}
21+
22+func (f *handlererr) Filecmd(r *sftp.Request) error {
23+ err := f.Handler.Filecmd(r)
24+ if err != nil {
25+ wish.Errorln(f.Handler.session, err)
26+ }
27+ return err
28+}
29+func (f *handlererr) Filelist(r *sftp.Request) (sftp.ListerAt, error) {
30+ result, err := f.Handler.Filelist(r)
31+ if err != nil {
32+ wish.Errorln(f.Handler.session, err)
33+ }
34+ return result, err
35+}
36+func (f *handlererr) Filewrite(r *sftp.Request) (io.WriterAt, error) {
37+ result, err := f.Handler.Filewrite(r)
38+ if err != nil {
39+ wish.Errorln(f.Handler.session, err)
40+ }
41+ return result, err
42+}
43+func (f *handlererr) Fileread(r *sftp.Request) (io.ReaderAt, error) {
44+ result, err := f.Handler.Fileread(r)
45+ if err != nil {
46+ wish.Errorln(f.Handler.session, err)
47+ }
48+ return result, err
49+}
send/sftp/sftp.go
link
+9
-5
+9
-5
1diff --git a/send/sftp/sftp.go b/send/sftp/sftp.go
2index b4c2003..489d443 100644
3--- a/send/sftp/sftp.go
4+++ b/send/sftp/sftp.go
5@@ -5,6 +5,7 @@ import (
6 "io"
7
8 "github.com/charmbracelet/ssh"
9+ "github.com/charmbracelet/wish"
10 "github.com/picosh/send/send/utils"
11 "github.com/pkg/sftp"
12 )
13@@ -25,19 +26,21 @@ func SubsystemHandler(writeHandler utils.CopyFromClientHandler) ssh.SubsystemHan
14 defer func() {
15 if r := recover(); r != nil {
16 writeHandler.GetLogger().Error("error running sftp middleware", "err", r)
17- _, _ = session.Stderr().Write([]byte("error running sftp middleware, check the flags you are using\r\n"))
18+ wish.Println(session, "error running sftp middleware, check the flags you are using")
19 }
20 }()
21
22 err := writeHandler.Validate(session)
23 if err != nil {
24- utils.ErrorHandler(session, err)
25+ wish.Errorln(session, err)
26 return
27 }
28
29- handler := &handler{
30- session: session,
31- writeHandler: writeHandler,
32+ handler := &handlererr{
33+ Handler: &handler{
34+ session: session,
35+ writeHandler: writeHandler,
36+ },
37 }
38
39 handlers := sftp.Handlers{
40@@ -51,6 +54,7 @@ func SubsystemHandler(writeHandler utils.CopyFromClientHandler) ssh.SubsystemHan
41
42 err = requestServer.Serve()
43 if err != nil && !errors.Is(err, io.EOF) {
44+ wish.Errorln(session, err)
45 writeHandler.GetLogger().Error("Error serving sftp subsystem", "err", err)
46 }
47 }