Replaced panic with error return value in normalizePaths()
This commit is contained in:
parent
4a484eed83
commit
6660e080f4
|
@ -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
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.2.0"
|
||||
var Version = "0.2.1"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue