cmd/stepd: Better error logging
This commit is contained in:
		
							parent
							
								
									ffb0eb894a
								
							
						
					
					
						commit
						0da05d465e
					
				@ -6,7 +6,6 @@ import "path"
 | 
				
			|||||||
import "io/fs"
 | 
					import "io/fs"
 | 
				
			||||||
import "strings"
 | 
					import "strings"
 | 
				
			||||||
import "net/http"
 | 
					import "net/http"
 | 
				
			||||||
import "html/template"
 | 
					 | 
				
			||||||
import "path/filepath"
 | 
					import "path/filepath"
 | 
				
			||||||
import "git.tebibyte.media/sashakoshka/step"
 | 
					import "git.tebibyte.media/sashakoshka/step"
 | 
				
			||||||
import "git.tebibyte.media/sashakoshka/goutil/container"
 | 
					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)
 | 
							remoteAddr = fmt.Sprintf("%s --??-> %s", addr, req.RemoteAddr)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	log.Println("(i)", req.Method, req.URL, "from", remoteAddr)
 | 
						log.Println("(i)", req.Method, req.URL, "from", remoteAddr)
 | 
				
			||||||
	// TODO log all this stuff
 | 
					 | 
				
			||||||
	filesystem := this.environment.GetFS()
 | 
						filesystem := this.environment.GetFS()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// normalize path
 | 
						// normalize path
 | 
				
			||||||
@ -87,13 +85,7 @@ func (this *handler) serveFile (res http.ResponseWriter, req *http.Request, file
 | 
				
			|||||||
		Data: req,
 | 
							Data: req,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		if tmplErr, ok := err.(*template.Error); ok {
 | 
							this.logErr(name, err)
 | 
				
			||||||
			log.Printf (
 | 
					 | 
				
			||||||
				"ERR document %s:%s: %s\n",
 | 
					 | 
				
			||||||
				name, tmplErr.Line, tmplErr.Description)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			log.Printf("ERR document %s: %v\n", 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)
 | 
						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) {
 | 
					func statFile (filesystem fs.FS, name string) (fs.FileInfo, error) {
 | 
				
			||||||
	if filesystem, ok := filesystem.(fs.StatFS); ok {
 | 
						if filesystem, ok := filesystem.(fs.StatFS); ok {
 | 
				
			||||||
		return filesystem.Stat(name)
 | 
							return filesystem.Stat(name)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user