From 0da05d465e6651d28b325e17d4635cc78103527d Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 5 Dec 2024 14:20:16 -0500 Subject: [PATCH] cmd/stepd: Better error logging --- cmd/stepd/handler.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/stepd/handler.go b/cmd/stepd/handler.go index e0d2637..12c891d 100644 --- a/cmd/stepd/handler.go +++ b/cmd/stepd/handler.go @@ -6,7 +6,6 @@ import "path" import "io/fs" import "strings" import "net/http" -import "html/template" import "path/filepath" import "git.tebibyte.media/sashakoshka/step" import "git.tebibyte.media/sashakoshka/goutil/container" @@ -26,7 +25,6 @@ func (this *handler) ServeHTTP (res http.ResponseWriter, req *http.Request) { remoteAddr = fmt.Sprintf("%s --??-> %s", addr, req.RemoteAddr) } log.Println("(i)", req.Method, req.URL, "from", remoteAddr) - // TODO log all this stuff filesystem := this.environment.GetFS() // normalize path @@ -87,13 +85,7 @@ func (this *handler) serveFile (res http.ResponseWriter, req *http.Request, file Data: req, }) if err != nil { - if tmplErr, ok := err.(*template.Error); ok { - log.Printf ( - "ERR document %s:%s: %s\n", - name, tmplErr.Line, tmplErr.Description) - } else { - log.Printf("ERR document %s: %v\n", name, err) - } + this.logErr(name, err) } } @@ -109,6 +101,10 @@ func (this *handler) serveError (res http.ResponseWriter, req *http.Request, sta log.Printf("ERR %d %s: %v\n", status, http.StatusText(status), message) } +func (this *handler) logErr (name string, err error) { + log.Printf("ERR %s: %v\n", name, err) +} + func statFile (filesystem fs.FS, name string) (fs.FileInfo, error) { if filesystem, ok := filesystem.(fs.StatFS); ok { return filesystem.Stat(name)