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

accepted · opened on 2024-09-09T04:26:26Z by erock
Help
# 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
# remove patchset
ssh pr.pico.sh ps rm ps-x
# checkout all patches
ssh pr.pico.sh pr print 20 | git am -3
# print a diff between the last two patches in a patch request
ssh pr.pico.sh pr diff 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
 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
 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 	}