From 35399619c2f38df3b8b9599a3e381c042ffc6a13 Mon Sep 17 00:00:00 2001 From: Bhoopesh Date: Thu, 19 Sep 2024 12:31:16 +0530 Subject: [PATCH] fix: remove panic statements and return errors Signed-off-by: Bhoopesh --- sztp-agent/pkg/dhcp/dbus.go | 4 ++-- sztp-agent/pkg/secureagent/daemon.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sztp-agent/pkg/dhcp/dbus.go b/sztp-agent/pkg/dhcp/dbus.go index 1220839..5f7a1ef 100644 --- a/sztp-agent/pkg/dhcp/dbus.go +++ b/sztp-agent/pkg/dhcp/dbus.go @@ -19,7 +19,7 @@ import ( func GetBootstrapURLsViaNetworkManager() ([]string, error) { conn, err := dbus.SystemBus() if err != nil { - panic(fmt.Errorf("failed to connect to system bus: %v", err)) + return nil, fmt.Errorf("failed to connect to system bus: %v", err) } // Get NetworkManager object @@ -28,7 +28,7 @@ func GetBootstrapURLsViaNetworkManager() ([]string, error) { var activeConnPaths []dbus.ObjectPath err = nm.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.NetworkManager", "ActiveConnections").Store(&activeConnPaths) if err != nil { - panic(fmt.Errorf("failed to get ActiveConnections property: %v", err)) + return nil, fmt.Errorf("failed to get ActiveConnections property: %v", err) } log.Println("[INFO] active connection paths: ", activeConnPaths) diff --git a/sztp-agent/pkg/secureagent/daemon.go b/sztp-agent/pkg/secureagent/daemon.go index 906d4b1..6bea027 100644 --- a/sztp-agent/pkg/secureagent/daemon.go +++ b/sztp-agent/pkg/secureagent/daemon.go @@ -55,7 +55,7 @@ func (a *Agent) performBootstrapSequence() error { urls := a.GetBootstrapURL() log.Println("[INFO] Performing the Bootstrap Sequence on each URL") for _, url := range urls { - urlCopy := url + urlCopy := url // found no other way to escape golangci-lint err = a.doRequestBootstrapServerOnboardingInfo(&urlCopy) if err != nil { log.Println("[ERROR] ", err.Error())