{"record":{"id":"d6c6c04a07d349b4","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-parse-metricpost-object-w","errorCode":null,"errorMessage":"cannot parse MetricPost object: %w","messagePattern":"cannot parse MetricPost object: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/protoparser/newrelic/parser.go","lineNumber":84,"sourceCode":"\t\t\t\t\t\terr = fmt.Errorf(\"cannot find EventObject: %w\", errLocal)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tif cap(rows) > len(rows) {\n\t\t\t\t\t\trows = rows[:len(rows)+1]\n\t\t\t\t\t} else {\n\t\t\t\t\t\trows = append(rows, Row{})\n\t\t\t\t\t}\n\t\t\t\t\tr := &rows[len(rows)-1]\n\t\t\t\t\tif errLocal := r.unmarshal(eventObject); errLocal != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"cannot unmarshal EventObject: %w\", errLocal)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\tr.Rows = rows\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot parse MetricPost object: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Row represents parsed row\ntype Row struct {\n\tTags      []Tag\n\tSamples   []Sample\n\tTimestamp int64\n}\n\n// Tag represents a key=value tag\ntype Tag struct {\n\tKey   []byte\n\tValue []byte\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/protoparser/newrelic/parser.go#L66-L102","documentation":"This is the outer wrapper returned by Unmarshal for any error that occurred while processing a MetricPost object inside the Visit callback (Events array errors, EventObject errors, row unmarshal errors). It wraps an inner error, so the root cause is always in the wrapped chain. It marks the request body as unparseable at one of the MetricPost objects.","triggerScenarios":"Any of: 'Events' value not an array; an Events element not an object; Row.unmarshal failing (bad timestamp) — for any MetricPost in the top-level array.","commonSituations":"Malformed payloads from misconfigured NewRelic agents, custom exporters, or intermediaries that transform the body; debugging a 400 response from the NewRelic import endpoint.","solutions":["Read the wrapped inner error (%w chain) to identify the exact field and cause.","Validate the payload structure: [{\"Events\": [{...event fields...}]}].","Use a JSON schema validator on the body before posting.","Fix the client that produced the malformed MetricPost object."],"exampleFix":"// before\n{\"Events\": [{\"timestamp\": \"not-a-number\"}]}\n// after\n{\"Events\": [{\"eventType\": \"Foo\", \"timestamp\": 1690000000}]}","handlingStrategy":"try-catch","validationCode":"func validatePayload(body []byte) error {\n\tvar posts []map[string]json.RawMessage\n\tif err := json.Unmarshal(body, &posts); err != nil {\n\t\treturn fmt.Errorf(\"invalid MetricPost array: %w\", err)\n\t}\n\treturn nil\n}","typeGuard":"func isMetricPostArray(v interface{}) bool {\n\tarr, ok := v.([]interface{})\n\tif !ok {\n\t\treturn false\n\t}\n\tfor _, e := range arr {\n\t\tif _, ok := e.(map[string]interface{}); !ok {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","tryCatchPattern":"if err := rows.Unmarshal(body); err != nil {\n\tvar inner error\n\tfor e := err; e != nil; e = errors.Unwrap(e) {\n\t\tinner = e\n\t}\n\tlog.Printf(\"MetricPost parse failed, root cause: %v (chain: %v)\", inner, err)\n\treturn err\n}","preventionTips":["Unwrap the error chain with errors.Unwrap to find the true cause.","Validate the whole payload against the NewRelic Event schema before posting.","Keep a sample of failing bodies for debugging.","Pin agent versions and test payloads after upgrades."],"tags":["json","newrelic","parsing","error-wrapping"],"backgroundTag":"json-schema-mismatch","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}