From 6660e080f40b601c9ffafff20aa2ad5540fa70d6 Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 9 Sep 2022 14:28:57 -0500 Subject: [PATCH] Replaced panic with error return value in normalizePaths() --- cmd/files.go | 6 +++--- cmd/version.go | 2 +- cmd/web.go | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index d06f803..498035b 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -87,17 +87,17 @@ func pickFile(fileList []string) (string, string) { return fileName, filePath } -func normalizePaths(args []string) []string { +func normalizePaths(args []string) ([]string, error) { var paths []string for i := 0; i < len(args); i++ { absolutePath, err := filepath.Abs(args[i]) if err != nil { - panic(err) + return nil, err } paths = append(paths, absolutePath) } - return paths + return paths, nil } diff --git a/cmd/version.go b/cmd/version.go index 91e1d11..aa7fa2e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.2.0" +var Version = "0.2.1" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 4528bf2..8645ee5 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -109,7 +109,10 @@ func doNothing(http.ResponseWriter, *http.Request) {} func ServePage(args []string) { defer HandleExit() - paths := normalizePaths(args) + paths, err := normalizePaths(args) + if err != nil { + log.Fatal(err) + } http.HandleFunc("/", servePageHandler(paths)) http.HandleFunc("/favicon.ico", doNothing)