fix some bad error printing

+ fixed "blog" not being highlighted in admin sidebar when visited
This commit is contained in:
ari melody 2025-11-08 15:16:43 +00:00
parent b7c1d85830
commit 84e40b837a
Signed by: ari
GPG key ID: CF99829C92678188
5 changed files with 29 additions and 27 deletions

View file

@ -81,6 +81,7 @@ func serveBlogIndex(app *model.AppState) http.Handler {
err = templates.BlogsTemplate.Execute(w, blogsData{
AdminPageData: core.AdminPageData{
Path: r.URL.Path,
Session: session,
},
TotalPosts: len(posts),
@ -118,6 +119,7 @@ func serveBlogPost(app *model.AppState) http.Handler {
err = templates.EditBlogTemplate.Execute(w, blogPostData{
AdminPageData: core.AdminPageData{
Path: r.URL.Path,
Session: session,
},
Post: post,

View file

@ -17,7 +17,7 @@ func serveArtists(app *model.AppState) http.Handler {
artists, err := controller.GetAllArtists(app.DB)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artists: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artists: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -32,7 +32,7 @@ func serveArtists(app *model.AppState) http.Handler {
Artists: artists,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin artists page: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin artists page: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -48,14 +48,14 @@ func serveArtist(app *model.AppState, artistID string) http.Handler {
http.NotFound(w, r)
return
}
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artist %s: %s\n", artistID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artist %s: %v\n", artistID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
credits, err := controller.GetArtistCredits(app.DB, artist.ID, true)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin artist page for %s: %s\n", artistID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artist credits for %s: %v\n", artistID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -72,7 +72,7 @@ func serveArtist(app *model.AppState, artistID string) http.Handler {
Credits: credits,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin artist page for %s: %s\n", artistID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin artist page for %s: %v\n", artistID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})

View file

@ -22,7 +22,7 @@ func serveReleases(app *model.AppState) http.Handler {
releases, err := controller.GetAllReleases(app.DB, false, 0, true)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch releases: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch releases: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -35,7 +35,7 @@ func serveReleases(app *model.AppState) http.Handler {
Releases: releases,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve releases page: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve releases page: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -46,7 +46,7 @@ func serveRelease(app *model.AppState, releaseID string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
release, err := controller.GetRelease(app.DB, releaseID, true)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch full release data for %s: %s\n", releaseID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch release %s: %v\n", releaseID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -69,7 +69,7 @@ func serveRelease(app *model.AppState, releaseID string) http.Handler {
Release: release,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin release page for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin release page for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -79,7 +79,7 @@ func serveEditRelease(app *model.AppState, releaseID string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
release, err := controller.GetRelease(app.DB, releaseID, true)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch full release data for %s: %s\n", releaseID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch release %s: %v\n", releaseID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -109,7 +109,7 @@ func serveEditCredits(release *model.Release) http.Handler {
w.Header().Set("Content-Type", "text/html")
err := templates.EditCreditsTemplate.Execute(w, release)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit credits component for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit credits component for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -119,7 +119,7 @@ func serveAddCredit(app *model.AppState, release *model.Release) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
artists, err := controller.GetArtistsNotOnRelease(app.DB, release.ID)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artists not on %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artists not on %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -135,7 +135,7 @@ func serveAddCredit(app *model.AppState, release *model.Release) http.Handler {
Artists: artists,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve add credits component for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve add credits component for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -146,7 +146,7 @@ func serveNewCredit(app *model.AppState) http.Handler {
artistID := r.PathValue("artistID")
artist, err := controller.GetArtist(app.DB, artistID)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artist %s: %s\n", artistID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch artist %s: %v\n", artistID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -158,7 +158,7 @@ func serveNewCredit(app *model.AppState) http.Handler {
w.Header().Set("Content-Type", "text/html")
err = templates.NewCreditTemplate.Execute(w, artist)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve new credit component for %s: %s\n", artist.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve new credit component for %s: %v\n", artist.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -169,7 +169,7 @@ func serveEditLinks(release *model.Release) http.Handler {
w.Header().Set("Content-Type", "text/html")
err := templates.EditLinksTemplate.Execute(w, release)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit links component for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit links component for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -185,7 +185,7 @@ func serveEditTracks(release *model.Release) http.Handler {
err := templates.EditTracksTemplate.Execute(w, editTracksData{ Release: release })
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit tracks component for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve edit tracks component for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -195,7 +195,7 @@ func serveAddTrack(app *model.AppState, release *model.Release) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tracks, err := controller.GetTracksNotOnRelease(app.DB, release.ID)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch tracks not on %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch tracks not on %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -211,7 +211,7 @@ func serveAddTrack(app *model.AppState, release *model.Release) http.Handler {
Tracks: tracks,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to add tracks component for %s: %s\n", release.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to add tracks component for %s: %v\n", release.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -222,7 +222,7 @@ func serveNewTrack(app *model.AppState) http.Handler {
trackID := r.PathValue("trackID")
track, err := controller.GetTrack(app.DB, trackID)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch track %s: %s\n", trackID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch track %s: %v\n", trackID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -234,7 +234,7 @@ func serveNewTrack(app *model.AppState) http.Handler {
w.Header().Set("Content-Type", "text/html")
err = templates.NewTrackTemplate.Execute(w, track)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve new track component for %s: %s\n", track.ID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve new track component for %s: %v\n", track.ID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})

View file

@ -17,7 +17,7 @@ func serveTracks(app *model.AppState) http.Handler {
tracks, err := controller.GetAllTracks(app.DB)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch tracks: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch tracks: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -32,7 +32,7 @@ func serveTracks(app *model.AppState) http.Handler {
Tracks: tracks,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin tracks page: %s\n", err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin tracks page: %v\n", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})
@ -44,7 +44,7 @@ func serveTrack(app *model.AppState, trackID string) http.Handler {
track, err := controller.GetTrack(app.DB, trackID)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin track page for %s: %s\n", trackID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch track %s: %v\n", trackID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -55,7 +55,7 @@ func serveTrack(app *model.AppState, trackID string) http.Handler {
releases, err := controller.GetTrackReleases(app.DB, track.ID, true)
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch releases for track %s: %s\n", trackID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to fetch releases for track %s: %v\n", trackID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
@ -72,7 +72,7 @@ func serveTrack(app *model.AppState, trackID string) http.Handler {
Releases: releases,
})
if err != nil {
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin track page for %s: %s\n", trackID, err)
fmt.Fprintf(os.Stderr, "WARN: Failed to serve admin track page for %s: %v\n", trackID, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
})