{"record":{"id":"faa1bd0b01ab4409","repo":"kataras/iris","slug":"multipart-related-next-part-w","errorCode":null,"errorMessage":"multipart related: next part: %w","messagePattern":"multipart related: next part: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context/context.go","lineNumber":3083,"sourceCode":"\t\t// * remember, Request.Body has no Bytes(), we have to consume them first\n\t\t// and after re-set them to the body, this is the only solution.\n\t\tbody, restoreBody, err := GetBody(ctx.request, true)\n\t\tif err != nil {\n\t\t\treturn MultipartRelated{}, fmt.Errorf(\"multipart related: body copy because of iris.Configuration.DisableBodyConsumptionOnUnmarshal: %w\", err)\n\t\t}\n\t\tsetBody(ctx.request, body) // so the ctx.request.Body works\n\t\tdefer restoreBody()        // so the next ctx.GetBody calls work.\n\t}\n\n\tmultipartReader := multipart.NewReader(ctx.request.Body, params[\"boundary\"])\n\tfor {\n\t\tpart, err := multipartReader.NextPart()\n\t\tif err != nil {\n\t\t\tif err == io.EOF {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\treturn MultipartRelated{}, fmt.Errorf(\"multipart related: next part: %w\", err)\n\t\t}\n\t\tdefer part.Close()\n\n\t\tb, err := io.ReadAll(part)\n\t\tif err != nil {\n\t\t\treturn MultipartRelated{}, fmt.Errorf(\"multipart related: next part: read: %w\", err)\n\t\t}\n\n\t\tcontentID := part.Header.Get(\"Content-ID\")\n\t\tcontentIDs = append(contentIDs, contentID)\n\t\tcontents[contentID] = MultipartRelatedContent{ // replace if same Content-ID appears, which it shouldn't.\n\t\t\tID:      contentID,\n\t\t\tHeaders: http.Header(part.Header),\n\t\t\tBody:    b,\n\t\t}\n\t}\n\n\tif len(contents) != len(contentIDs) {","sourceCodeStart":3065,"sourceCodeEnd":3101,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L3065-L3101","documentation":"Returned by ReadMultipartRelated when multipartReader.NextPart() fails with an error other than io.EOF while iterating the parts of a multipart/related body. It wraps the underlying parsing error and means the multipart stream was malformed or the connection failed between parts.","triggerScenarios":"ctx.ReadMultipartRelated where NextPart returns a non-EOF error: malformed boundary, truncated body, missing final boundary, or an underlying read error on the connection.","commonSituations":"Clients generating malformed multipart/related payloads (SOAP MTOM, XOP packages); interrupted uploads; mismatched boundary parameter in Content-Type; proxies re-encoding the body.","solutions":["Inspect the wrapped error (%w) to distinguish parse errors from network failures.","Validate the client's Content-Type boundary matches the actual delimiter used.","Return 400 to the client for malformed multipart payloads.","Capture the raw body (when recording is enabled) to debug the exact bytes that failed."],"exampleFix":"// before\nmr, err := ctx.ReadMultipartRelated()\nif err != nil { return err }\n// after\nmr, err := ctx.ReadMultipartRelated()\nif err != nil {\n    ctx.StatusCode(iris.StatusBadRequest)\n    return fmt.Errorf(\"invalid multipart/related payload: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"ct := ctx.GetContentType()\nif !strings.HasPrefix(ct, \"multipart/related\") {\n    return errors.New(\"expected multipart/related content type\")\n}","typeGuard":"func isMultipartRelated(ctx *context.Context) bool {\n    return strings.HasPrefix(ctx.GetContentType(), \"multipart/related\")\n}","tryCatchPattern":"mr, err := ctx.ReadMultipartRelated()\nif err != nil {\n    if strings.Contains(err.Error(), \"next part:\") && !strings.Contains(err.Error(), \"read:\") {\n        ctx.StatusCode(iris.StatusBadRequest)\n        return fmt.Errorf(\"malformed multipart/related: %w\", err)\n    }\n    return err\n}","preventionTips":["Verify the client's boundary parameter matches the actual payload delimiters","Return 400 for parse errors instead of 500","Capture raw bodies when recording is enabled to debug malformed payloads"],"tags":["go","iris","multipart","parsing"],"backgroundTag":"malformed-multipart-body","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}