implement /reset:cwd (fix for #278) and more (#392)

* checkpoint some ideas on a new branch

* checkpoint on new errors / errorcode passing

* get CodedError piped all the way through to infomsg

* implement a /reset:cwd command to deal with cases when the cwd is invalid.  other assorted debugging, utility, and fixups

* on invalid cwd, show message to run /reset:cwd
This commit is contained in:
Mike Sawka
2024-03-06 16:37:54 -08:00
committed by GitHub
parent 33fc3518c0
commit 4357bcf1c8
18 changed files with 301 additions and 40 deletions
+16 -5
View File
@@ -72,6 +72,10 @@ const (
ShellType_zsh = "zsh"
)
const (
EC_InvalidCwd = "ERRCWD"
)
const PacketSenderQueueSize = 20
const PacketEOFStr = "EOF"
@@ -491,11 +495,12 @@ func MakeCompGenPacket() *CompGenPacketType {
}
type ResponsePacketType struct {
Type string `json:"type"`
RespId string `json:"respid"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Data interface{} `json:"data,omitempty"`
Type string `json:"type"`
RespId string `json:"respid"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
ErrorCode string `json:"errorcode,omitempty"` // can be used for structured errors
Data interface{} `json:"data,omitempty"`
}
func (*ResponsePacketType) GetType() string {
@@ -516,6 +521,9 @@ func (p *ResponsePacketType) Err() error {
}
if !p.Success {
if p.Error != "" {
if p.ErrorCode != "" {
return &base.CodedError{ErrorCode: p.ErrorCode, Err: errors.New(p.Error)}
}
return errors.New(p.Error)
}
return fmt.Errorf("rpc failed")
@@ -531,6 +539,9 @@ func (p *ResponsePacketType) String() string {
}
func MakeErrorResponsePacket(reqId string, err error) *ResponsePacketType {
if codedErr, ok := err.(*base.CodedError); ok {
return &ResponsePacketType{Type: ResponsePacketStr, RespId: reqId, Error: codedErr.Err.Error(), ErrorCode: codedErr.ErrorCode}
}
return &ResponsePacketType{Type: ResponsePacketStr, RespId: reqId, Error: err.Error()}
}