Skip to content

Commit

Permalink
feat: enhance settings content rendering with threshold handling and …
Browse files Browse the repository at this point in the history
…improved error logging

- Added special handling for species thresholds in the renderSettingsContent method, converting thresholds into a formatted string for better display.
- Improved error logging by providing a detailed template data dump when rendering fails, aiding in debugging and issue resolution.
  • Loading branch information
tphakala committed Jan 8, 2025
1 parent e304ecd commit d6f499f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/httpcontroller/template_renderers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (s *Server) renderSettingsContent(c echo.Context) (template.HTML, error) {
if templateName == "detectionfiltersSettings" ||
templateName == "speciesSettings" {
data["PreparedSpecies"] = s.prepareSpeciesData()

// For thresholds, we need to handle the map specially
var thresholdStrings []string
for species, threshold := range s.Settings.Realtime.Species.Thresholds {
thresholdStrings = append(thresholdStrings, fmt.Sprintf("[%s: %f]", species, threshold))

Check failure on line 138 in internal/httpcontroller/template_renderers.go

View workflow job for this annotation

GitHub Actions / golangci / lint

printf: fmt.Sprintf format %f has arg threshold of wrong type github.com/tphakala/birdnet-go/internal/conf.SpeciesThreshold (govet)
}
}

// DEBUG Log the species settings
Expand All @@ -142,10 +148,11 @@ func (s *Server) renderSettingsContent(c echo.Context) (template.HTML, error) {

// Handle rendering errors
if err != nil {
log.Printf("Error rendering settings content: %v", err)
log.Printf("ERROR: Failed to render settings content: %v", err)
// Log the template data that caused the error
log.Printf("ERROR: Template data dump: %+v", data)
return "", err
}

// Return the rendered HTML
return template.HTML(buf.String()), nil
}

0 comments on commit d6f499f

Please sign in to comment.