{"record":{"id":"982d2b055a2a8ea4","repo":"theonedev/onedev","slug":"invalid-publish-request-body","errorCode":null,"errorMessage":"Invalid publish request body","messagePattern":"Invalid publish request body","errorType":"http","errorClass":"ClientException","httpStatus":400,"severity":"error","filePath":"server-plugin/server-plugin-pack-cargo/src/main/java/io/onedev/server/plugin/pack/cargo/CargoPackHandler.java","lineNumber":286,"sourceCode":"\t\t\tvar publishMetadata = (ObjectNode) objectMapper.readTree(data.getMetadata());\n\t\t\tvar indexEntry = objectMapper.createObjectNode();\n\t\t\tindexEntry.put(\"name\", publishMetadata.path(\"name\").asText());\n\t\t\tindexEntry.put(\"vers\", publishMetadata.path(\"vers\").asText());\n\t\t\tvar depsNode = publishMetadata.path(\"deps\");\n\t\t\tindexEntry.set(\"deps\", depsNode instanceof ArrayNode ? toIndexDeps((ArrayNode) depsNode) : objectMapper.createArrayNode());\n\t\t\tindexEntry.put(\"cksum\", data.getSha256BlobHash());\n\t\t\tindexEntry.set(\"features\", publishMetadata.path(\"features\"));\n\t\t\tindexEntry.put(\"yanked\", data.isYanked());\n\t\t\tif (publishMetadata.hasNonNull(\"links\"))\n\t\t\t\tindexEntry.set(\"links\", publishMetadata.get(\"links\"));\n\t\t\tif (publishMetadata.hasNonNull(\"rust_version\"))\n\t\t\t\tindexEntry.set(\"rust_version\", publishMetadata.get(\"rust_version\"));\n\t\t\tindexEntry.put(\"v\", 2);\n\t\t\treturn objectMapper.writer()\n\t\t\t\t\t.without(SerializationFeature.INDENT_OUTPUT)\n\t\t\t\t\t.writeValueAsBytes(indexEntry);\n\t\t} catch (IOException e) {\n\t\t\tthrow new ClientException(SC_BAD_REQUEST, \"Invalid publish request body\");\n\t\t}\n\t}\n\n\tprivate ArrayNode toIndexDeps(ArrayNode publishDeps) {\n\t\tvar indexDeps = objectMapper.createArrayNode();\n\t\tfor (var publishDep : publishDeps) {\n\t\t\tvar dep = objectMapper.createObjectNode();\n\t\t\tvar explicitName = publishDep.path(\"explicit_name_in_toml\");\n\t\t\tdep.put(\"name\", explicitName.isMissingNode() || explicitName.isNull()\n\t\t\t\t\t? publishDep.path(\"name\").asText()\n\t\t\t\t\t: explicitName.asText());\n\t\t\tdep.put(\"req\", publishDep.path(\"version_req\").asText());\n\t\t\tdep.set(\"features\", publishDep.path(\"features\"));\n\t\t\tdep.put(\"optional\", publishDep.path(\"optional\").asBoolean(false));\n\t\t\tdep.put(\"default_features\", publishDep.path(\"default_features\").asBoolean(true));\n\t\t\tdep.set(\"target\", publishDep.path(\"target\"));\n\t\t\tdep.put(\"kind\", publishDep.path(\"kind\").asText(\"normal\"));\n\t\t\tdep.set(\"registry\", publishDep.path(\"registry\"));","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-plugin/server-plugin-pack-cargo/src/main/java/io/onedev/server/plugin/pack/cargo/CargoPackHandler.java#L268-L304","documentation":"Thrown by CargoPackHandler.getIndexEntry when serializing a stored crate's index entry fails with an IOException. Despite the message, this happens while regenerating the sparse-index entry from stored publish metadata (readTree/writeValueAsBytes), typically because stored metadata JSON is unreadable/corrupt. It is surfaced to the client as an HTTP 400.","triggerScenarios":"A cargo client requests the sparse index (GET /index/... crate name) and the server cannot parse the stored metadata JSON of a published version into an ObjectNode, or Jackson fails to serialize the generated index entry.","commonSituations":"Corrupted CargoData.metadata stored during a faulty publish; manual DB edits to pack metadata; Jackson serialization feature conflicts after plugin upgrade.","solutions":["Inspect CargoData.metadata for the affected pack and fix or re-publish the crate","Re-publish the affected crate version to regenerate clean metadata","Check server logs for the underlying IOException to identify the corrupt record","Upgrade/verify the cargo pack plugin and Jackson versions are consistent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// client-side: nothing to pre-validate; server-side validate stored metadata parses\nJsonNode meta = objectMapper.readTree(data.getMetadata()); // throws -> corrupt record","typeGuard":"if (meta == null || !meta.isObject()) { /* corrupt metadata, republish */ }","tryCatchPattern":"try { entry = getIndexEntry(pack); } catch (ClientException e) { logger.error(\"corrupt metadata for pack\", e); republish(pack); }","preventionTips":["Re-publish crates whose index fetches fail","Avoid manual DB edits to pack metadata","Keep plugin/Jackson versions consistent","Log the underlying IOException cause"],"tags":["cargo","registry","json","index"],"backgroundTag":"json-marshal-failed","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}