{"record":{"id":"51e6458fef30db52","repo":"quickwit-oss/quickwit","slug":"encountered-unknown-command-code-other","errorCode":null,"errorMessage":"Encountered unknown command: code {other}","messagePattern":"Encountered unknown command: code (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-ingest/src/doc_batch.rs","lineNumber":46,"sourceCode":"    Commit,\n    // ... more to come?\n}\n\n/// We can use this byte to track both commands and their version changes\n/// If serialization protocol changes, we can just use the next number\n#[derive(Debug)]\n#[repr(u8)]\npub enum DocCommandCode {\n    IngestV1 = 0,\n    CommitV1 = 1,\n}\n\nimpl From<u8> for DocCommandCode {\n    fn from(value: u8) -> Self {\n        match value {\n            0 => DocCommandCode::IngestV1,\n            1 => DocCommandCode::CommitV1,\n            other => panic!(\"Encountered unknown command: code {other}\"),\n        }\n    }\n}\n\nimpl<T> DocCommand<T>\nwhere T: Buf + Default\n{\n    /// Returns the binary serialization code for the current version of this command.\n    pub fn code(&self) -> DocCommandCode {\n        match self {\n            DocCommand::Ingest { payload: _ } => DocCommandCode::IngestV1,\n            DocCommand::Commit => DocCommandCode::CommitV1,\n        }\n    }\n\n    /// Builds a command for bytes::Buf\n    pub fn read(mut buf: T) -> Self {\n        match buf.get_u8().into() {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-ingest/src/doc_batch.rs#L28-L64","documentation":"The REST search handler converts an Elasticsearch-style aggregation request (`aggs` JSON value) into the proto SearchRequest by serializing it to a JSON string with serde_json. `.expect` fires if `serde_json::to_string` fails, meaning the aggregation JSON could not be serialized. Since the input is already a parsed JSON value this indicates a non-serializable value (e.g. NaN/Infinity floats) or an aggregation type the serializer rejects.","triggerScenarios":"Sending a POST /api/v1/_search (or _search/async) request with an `aggs` payload containing values serde_json cannot serialize — most commonly non-finite floats (NaN, Infinity) produced by numeric expressions in the aggregation body.","commonSituations":"Clients templating aggregations with computed numbers that yield NaN/Infinity; passing unusual JSON values (e.g. from YAML with .nan/.inf) in aggs; programmatic clients building aggs from floats without validating finiteness.","solutions":["Inspect the `aggs` field of the failing request and remove or fix non-finite numbers (NaN, Infinity).","Validate the aggregation JSON before sending: ensure all numeric literals are finite.","If the aggs come from a template or generated config, fix the generator to emit finite values.","If aggregation definitions are valid but rejected, check for a version mismatch between client and server aggregation schema."],"exampleFix":"// before\nserde_json::to_string(&agg).expect(\"could not serialize JsonValue\")\n// after\nserde_json::to_string(&agg).map_err(|err| {\n    anyhow::anyhow!(\"failed to serialize aggregation request: {err}\")\n})?","handlingStrategy":"validation","validationCode":"// validate aggs before sending\nfunction validateAggs(aggs) {\n  for (const n of extractNumbers(aggs)) {\n    if (!Number.isFinite(n)) throw new Error(`aggs contains non-finite number: ${n}`);\n  }\n}\nvalidateAggs(requestBody.aggs);","typeGuard":"const isFiniteNumber = (v) => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":"// client-side: reject bad aggs before the request reaches the server\ntry {\n  validateAggs(aggs);\n} catch (e) {\n  return res.status(400).json({ error: e.message });\n}","preventionTips":["Never embed NaN/Infinity in aggregation bodies.","Sanitize numbers generated by templates or computed expressions.","Prefer YAML-safe values (avoid .nan/.inf) feeding into aggs.","Pin client/server versions so aggregation schemas match."],"tags":["rust","serde","json","aggregations","rest-api"],"backgroundTag":"json-serialization-failed","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}