dashboard / erock/pubsub / refactor: unsub method to interface #20 rss

accepted · opened on 2024-09-09T04:26:26Z by erock
Help
checkout latest patchset:
ssh pr.pico.sh print pr-20 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 20
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 20
accept PR:
ssh pr.pico.sh pr accept 20
close PR:
ssh pr.pico.sh pr close 20

Logs

erock created pr with ps-36 on 2024-08-20T03:19:05Z

Patchsets

ps-36 by erock on 2024-08-20T03:19:05Z

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