From 0dbaddc7bec1365d480aad7cf0505067a13ef32a Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:05:23 +0100 Subject: [PATCH] [client] Don't fail debug if log file is console (#3103) --- client/server/debug.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/client/server/debug.go b/client/server/debug.go index 9dfde0367f3..3c4967b4e41 100644 --- a/client/server/debug.go +++ b/client/server/debug.go @@ -139,10 +139,6 @@ func (s *Server) DebugBundle(_ context.Context, req *proto.DebugBundleRequest) ( s.mutex.Lock() defer s.mutex.Unlock() - if s.logFile == "console" { - return nil, fmt.Errorf("log file is set to console, cannot create debug bundle") - } - bundlePath, err := os.CreateTemp("", "netbird.debug.*.zip") if err != nil { return nil, fmt.Errorf("create zip file: %w", err) @@ -185,17 +181,7 @@ func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleReques } if req.GetSystemInfo() { - if err := s.addRoutes(req, anonymizer, archive); err != nil { - log.Errorf("Failed to add routes to debug bundle: %v", err) - } - - if err := s.addInterfaces(req, anonymizer, archive); err != nil { - log.Errorf("Failed to add interfaces to debug bundle: %v", err) - } - - if err := s.addFirewallRules(req, anonymizer, archive); err != nil { - log.Errorf("Failed to add firewall rules to debug bundle: %v", err) - } + s.addSystemInfo(req, anonymizer, archive) } if err := s.addNetworkMap(req, anonymizer, archive); err != nil { @@ -206,8 +192,10 @@ func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleReques log.Errorf("Failed to add state file to debug bundle: %v", err) } - if err := s.addLogfile(req, anonymizer, archive); err != nil { - return fmt.Errorf("add log file: %w", err) + if s.logFile != "console" { + if err := s.addLogfile(req, anonymizer, archive); err != nil { + return fmt.Errorf("add log file: %w", err) + } } if err := archive.Close(); err != nil { @@ -216,6 +204,20 @@ func (s *Server) createArchive(bundlePath *os.File, req *proto.DebugBundleReques return nil } +func (s *Server) addSystemInfo(req *proto.DebugBundleRequest, anonymizer *anonymize.Anonymizer, archive *zip.Writer) { + if err := s.addRoutes(req, anonymizer, archive); err != nil { + log.Errorf("Failed to add routes to debug bundle: %v", err) + } + + if err := s.addInterfaces(req, anonymizer, archive); err != nil { + log.Errorf("Failed to add interfaces to debug bundle: %v", err) + } + + if err := s.addFirewallRules(req, anonymizer, archive); err != nil { + log.Errorf("Failed to add firewall rules to debug bundle: %v", err) + } +} + func (s *Server) addReadme(req *proto.DebugBundleRequest, archive *zip.Writer) error { if req.GetAnonymize() { readmeReader := strings.NewReader(readmeContent)