diff --git a/config/config.go b/config/config.go index ba6cc53..0dd5c92 100644 --- a/config/config.go +++ b/config/config.go @@ -319,7 +319,8 @@ func (cs *ConfigService) LoadConfig() error { func (cs *ConfigService) WriteConfig() { s, err := yaml.Marshal(cs.Config) if err != nil { - panic(err) + log.Printf("error writing config: %s", err) + os.Exit(1) } path := cs.ConfigPath diff --git a/download/download.go b/download/download.go index 4d9108f..6c5c1e2 100644 --- a/download/download.go +++ b/download/download.go @@ -429,8 +429,6 @@ func (dl *Download) updateMetadata(s string) { p, err := strconv.ParseFloat(matches[1], 32) if err == nil { dl.Percent = float32(p) - } else { - panic(err) } } diff --git a/download/download_test.go b/download/download_test.go index 0c07deb..8dd8ec7 100644 --- a/download/download_test.go +++ b/download/download_test.go @@ -317,7 +317,7 @@ func TestUpdateMetadataSingle(t *testing.T) { [youtube] 2WoDQBhJCVQ: Downloading android player API JSON [info] 2WoDQBhJCVQ: Downloading 1 format(s): 137+140 [info] Writing video metadata as JSON to: The Greatest Shot In Television [2WoDQBhJCVQ].info.json -[download] Destination: The Greatest Shot In Television [2WoDQBhJCVQ].f137.mp4 +[debug] Invoking hlsnative downloader on "https://example.org/urls/1.2.3.4% [download] 0.0% of 12.82MiB at 510.94KiB/s ETA 00:26 [download] 0.0% of 12.82MiB at 966.50KiB/s ETA 00:13 [download] 0.1% of 12.82MiB at 1.54MiB/s ETA 00:08 diff --git a/web/web.go b/web/web.go index 33cabfe..aeea5bd 100644 --- a/web/web.go +++ b/web/web.go @@ -92,7 +92,10 @@ func homeHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Man t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/menu.tmpl", "data/templates/index.tmpl") if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } type Info struct { @@ -113,7 +116,10 @@ func homeHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Man defer dm.Lock.Unlock() err = t.ExecuteTemplate(w, "layout", info) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } } } @@ -149,12 +155,18 @@ func configHandler() func(w http.ResponseWriter, r *http.Request) { t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/menu.tmpl", "data/templates/config.tmpl") if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } err = t.ExecuteTemplate(w, "layout", nil) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } } } @@ -167,7 +179,10 @@ func configRESTHandler(cs *config.ConfigService) func(w http.ResponseWriter, r * log.Printf("Updating config") b, err := io.ReadAll(r.Body) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } err = cs.Config.UpdateFromJSON(b) @@ -221,7 +236,10 @@ func fetchInfoOneRESTHandler(cs *config.ConfigService, dm *download.Manager) fun b, err := io.ReadAll(r.Body) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } err = json.Unmarshal(b, &thisReq) @@ -271,7 +289,10 @@ func fetchInfoRESTHandler(dm *download.Manager) func(w http.ResponseWriter, r *h b, err := dm.DownloadsAsJSON() if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } _, err = w.Write(b) if err != nil { @@ -307,14 +328,20 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/popup.tmpl") if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } templateData := map[string]interface{}{"dl": dl, "config": cs.Config, "canStop": download.CanStopDownload, "Version": vm.GetInfo()} err = t.ExecuteTemplate(w, "layout", templateData) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } return } else if method == "POST" { @@ -389,13 +416,19 @@ func fetchHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Ma t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/popup_create.tmpl") if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } templateData := map[string]interface{}{"config": cs.Config, "url": url[0], "Version": vm.GetInfo()} err = t.ExecuteTemplate(w, "layout", templateData) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } } @@ -412,13 +445,19 @@ func bulkHandler(cs *config.ConfigService, vm *version.Manager, dm *download.Man t, err := template.ParseFS(webFS, "data/templates/layout.tmpl", "data/templates/menu.tmpl", "data/templates/bulk.tmpl") if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } templateData := map[string]interface{}{"config": cs.Config, "Version": vm.GetInfo()} err = t.ExecuteTemplate(w, "layout", templateData) if err != nil { - panic(err) + log.Printf("error: %s", err) + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return } return