From a376685cd907b8d67931e486e71b6878e3f1417d Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 2 Nov 2023 05:51:54 +0000 Subject: [PATCH 1/4] replace panic with error on rpc overview --- pkg/visor/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 5a1d88084..8b254084b 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -153,10 +153,10 @@ func (v *Visor) Overview() (*Overview, error) { var publicIP string var isSymmetricNAT bool if v == nil { - panic("v is nil") + return &Overview{}, errors.New("v is nil") } if v.tpM == nil { - panic("tpM is nil") + return &Overview{}, errors.New("tpM is nil") } v.tpM.WalkTransports(func(tp *transport.ManagedTransport) bool { tSummaries = append(tSummaries, From cc50c1d419af688ae35d0175db99c26d9361dfc6 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 2 Nov 2023 05:52:42 +0000 Subject: [PATCH 2/4] add condition on use tpM.WalkTransports on get list of transports by rpc --- pkg/visor/api.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 8b254084b..a49614d69 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -1064,12 +1064,14 @@ func (v *Visor) Transports(types []string, pks []cipher.PubKey, logs bool) ([]*T } return true } - v.tpM.WalkTransports(func(tp *transport.ManagedTransport) bool { - if typeIncluded(tp.Type()) && pkIncluded(v.tpM.Local(), tp.Remote()) { - result = append(result, newTransportSummary(v.tpM, tp, logs, v.router.SetupIsTrusted(tp.Remote()))) - } - return true - }) + if v.tpM != nil { + v.tpM.WalkTransports(func(tp *transport.ManagedTransport) bool { + if typeIncluded(tp.Type()) && pkIncluded(v.tpM.Local(), tp.Remote()) { + result = append(result, newTransportSummary(v.tpM, tp, logs, v.router.SetupIsTrusted(tp.Remote()))) + } + return true + }) + } return result, nil } From 3d020bc3304537954d7ebca0031bdad435f3a573 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 2 Nov 2023 05:54:22 +0000 Subject: [PATCH 3/4] improve error values --- pkg/visor/api.go | 4 ++-- pkg/visor/visor.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/visor/api.go b/pkg/visor/api.go index a49614d69..6f401e5d5 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -153,10 +153,10 @@ func (v *Visor) Overview() (*Overview, error) { var publicIP string var isSymmetricNAT bool if v == nil { - return &Overview{}, errors.New("v is nil") + return &Overview{}, ErrVisorNotAvailable } if v.tpM == nil { - return &Overview{}, errors.New("tpM is nil") + return &Overview{}, ErrTrpMangerNotAvailable } v.tpM.WalkTransports(func(tp *transport.ManagedTransport) bool { tSummaries = append(tSummaries, diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index 67b2a955e..7f90b5664 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -42,6 +42,8 @@ import ( ) var ( + // ErrVisorNotAvailable represents error for unavailable visor + ErrVisorNotAvailable = errors.New("no visor available") // ErrAppProcNotRunning represents lookup error for App related calls. ErrAppProcNotRunning = errors.New("no process of given app is running") // ErrProcNotAvailable represents error for unavailable process manager From a1b6446dee6bd1e9c1c9cb5c5c97e680a7adbca3 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Thu, 2 Nov 2023 05:57:09 +0000 Subject: [PATCH 4/4] add more condition for check tpM is available or not --- pkg/visor/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 6f401e5d5..c686df664 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -1032,6 +1032,9 @@ func (v *Visor) Ports() (map[string]PortDetail, error) { // TransportTypes implements API. func (v *Visor) TransportTypes() ([]string, error) { var types []string + if v.tpM == nil { + return types, ErrTrpMangerNotAvailable + } for _, netType := range v.tpM.Networks() { types = append(types, string(netType)) }