{"record":{"id":"82181ef77d62a9f6","repo":"SigNoz/signoz","slug":"err-error-82181e","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"pkg/query-service/app/http_handler.go","lineNumber":289,"sourceCode":"\tdefault:\n\t\ttyp = model.ErrorInternal\n\t}\n\n\treturn &model.ApiError{Typ: typ, Err: err}\n}\n\n// todo(remove): Implemented at render package (github.com/SigNoz/signoz/pkg/http/render) with the new error structure\nfunc RespondError(w http.ResponseWriter, apiErr model.BaseApiError, data interface{}) {\n\tjson := jsoniter.ConfigCompatibleWithStandardLibrary\n\tb, err := json.Marshal(&ApiResponse{\n\t\tStatus:    statusError,\n\t\tErrorType: apiErr.Type(),\n\t\tError:     apiErr.Error(),\n\t\tData:      data,\n\t})\n\tif err != nil {\n\t\tslog.Error(\"error marshalling json response\", errors.Attr(err))\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar code int\n\tswitch apiErr.Type() {\n\tcase model.ErrorBadData:\n\t\tcode = http.StatusBadRequest\n\tcase model.ErrorExec:\n\t\tcode = 422\n\tcase model.ErrorCanceled, model.ErrorTimeout:\n\t\tcode = http.StatusServiceUnavailable\n\tcase model.ErrorInternal:\n\t\tcode = http.StatusInternalServerError\n\tcase model.ErrorNotFound:\n\t\tcode = http.StatusNotFound\n\tcase model.ErrorNotImplemented:\n\t\tcode = http.StatusNotImplemented\n\tcase model.ErrorUnauthorized:","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/http_handler.go#L271-L307","documentation":"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).","triggerScenarios":"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.","commonSituations":"Rare; most plausibly invalid UTF-8 in an underlying error message (e.g. binary bytes from a corrupted rule payload bubbling into apiErr.Error()).","solutions":["Sanitize non-UTF8 data in rule payloads before it becomes part of error strings","If observed, capture the slog 'error marshalling json response' log entry which includes errors.Attr(err) with the root cause","Treat occurrence as a bug: the client received a plaintext 500 instead of the structured error"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"utf8.ValidString(apiErr.Error())","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize non-UTF8 bytes out of error messages","Watch for the 'error marshalling json response' slog entry to find the cause"],"tags":["http","json","marshal","rules-api"],"backgroundTag":"http-error-rendering-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}