SigNoz/signoz · warning

err.Error()

Error message

err.Error()

What it means

RespondError marshals an ApiResponse wrapping the API error; if json.Marshal fails it logs and calls http.Error with the marshal error text and a plain 500, bypassing the structured error format the API normally returns. Like error 795 this is a defensive branch for an 'impossible' condition (ApiResponse of strings should always marshal).

Source

Thrown at pkg/query-service/app/http_handler.go:289

	default:
		typ = model.ErrorInternal
	}

	return &model.ApiError{Typ: typ, Err: err}
}

// todo(remove): Implemented at render package (github.com/SigNoz/signoz/pkg/http/render) with the new error structure
func RespondError(w http.ResponseWriter, apiErr model.BaseApiError, data interface{}) {
	json := jsoniter.ConfigCompatibleWithStandardLibrary
	b, err := json.Marshal(&ApiResponse{
		Status:    statusError,
		ErrorType: apiErr.Type(),
		Error:     apiErr.Error(),
		Data:      data,
	})
	if err != nil {
		slog.Error("error marshalling json response", errors.Attr(err))
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var code int
	switch apiErr.Type() {
	case model.ErrorBadData:
		code = http.StatusBadRequest
	case model.ErrorExec:
		code = 422
	case model.ErrorCanceled, model.ErrorTimeout:
		code = http.StatusServiceUnavailable
	case model.ErrorInternal:
		code = http.StatusInternalServerError
	case model.ErrorNotFound:
		code = http.StatusNotFound
	case model.ErrorNotImplemented:
		code = http.StatusNotImplemented
	case model.ErrorUnauthorized:

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Sanitize non-UTF8 data in rule payloads before it becomes part of error strings
  2. If observed, capture the slog 'error marshalling json response' log entry which includes errors.Attr(err) with the root cause
  3. Treat occurrence as a bug: the client received a plaintext 500 instead of the structured error
Defensive patterns

Strategy: fallback

Validate before calling

utf8.ValidString(apiErr.Error())

Prevention

When it happens

Trigger: Hit by rule endpoints (listRules, getRule, createRule, editRule, deleteRule, patchRule) only if the constructed ApiResponse fails to serialize — practically limited to causes whose Error() string or Data contains invalid UTF-8 that json.Marshal rejects.

Common situations: Rare; most plausibly invalid UTF-8 in an underlying error message (e.g. binary bytes from a corrupted rule payload bubbling into apiErr.Error()).

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/82181ef77d62a9f6. Report an issue: GitHub.