Skip to content

Standardize UI error logging: consolidate repeated 'failed to load' blocks #175

Description

@cawalch

Problem

12+ instances of "failed to load ... for UI" logging are scattered across 9 handler files with inconsistent APIs:

Inconsistent logging calls

File Line API used
ui_sources.go 155 h.logger().ErrorContext(ctx, ...)
ui_sites.go 137 h.logger().Error(...) (no ctx)
ui_iocs.go 76 h.logger().ErrorContext(ctx, ...)
ui_jobs.go 1253 h.logger().ErrorContext(ctx, ...)
ui_secrets.go 33 h.logger().Error(...) (no ctx)
ui_alerts.go 129, 158, 219 h.logger().ErrorContext(ctx, ...)
ui_dashboard.go 264 h.logger().Error(...) (no ctx)
ui_alert_sinks.go 63, 97 h.logger().Error(...) / h.logger().Warn(...)
ui_allowlist.go 23 h.logger().Error(...) (no ctx)

Some use ErrorContext(ctx, ...) with structured context, others fall back to Error(...) without the request context — making traceability inconsistent.

Impact

  • Telemetry gap: Without ctx, logs lack request tracing metadata (request ID, correlation ID).
  • Inconsistent UX: Some errors render via RenderError, others use raw http.Error(w, ...).
  • HTMX awareness missing: Error responses don't consistently account for HTMX partial vs full-page requests.

Proposed fix

Expand the existing error_renderer.go / RenderError to cover list handler errors:

// LogAndRenderListError logs a structured error and renders an appropriate response.
func LogAndRenderListError(
  ctx context.Context, logger *slog.Logger, w http.ResponseWriter, r *http.Request,
  err error, msg string, basePath string, pageMeta PageMeta,
) {
  logger.ErrorContext(ctx, msg, "error", err)
  RenderError(ctx, w, r, err, basePath, pageMeta)
}

Replace all 12+ instances with a single call. Standardize on ErrorContext everywhere.

Files to change

  • services/merrymaker-go/internal/http/error_renderer.go — expand helpers
  • All 9 handler files listed above

Acceptance criteria

  • All error logging uses ErrorContext(ctx, ...) consistently
  • Single helper in error_renderer.go handles log + render for list errors
  • No behavior change to end users' error experience
  • Lint + tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update go code

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions