Replaced panic with error return value in normalizePaths()

This commit is contained in:
Seednode 2022-09-09 14:28:57 -05:00
parent 4a484eed83
commit 6660e080f4
3 changed files with 8 additions and 5 deletions

View File

@ -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
}

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)
var Version = "0.2.0"
var Version = "0.2.1"
func init() {
rootCmd.AddCommand(versionCmd)

View File

@ -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)