{"record":{"id":"c2503b5b8d380598","repo":"denoland/deno","slug":"invalid-mutation-type-without-value","errorCode":null,"errorMessage":"Invalid mutation '${type}' without value","messagePattern":"Invalid mutation '(.+?)' without value","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/kv/01_db.ts","lineNumber":499,"sourceCode":"      switch (mutation.type) {\n        case \"delete\":\n          type = \"delete\";\n          if (mutation.value) {\n            throw new TypeError(\"Invalid mutation 'delete' with value\");\n          }\n          break;\n        case \"set\":\n          if (typeof mutation.expireIn === \"number\") {\n            expireIn = mutation.expireIn;\n          }\n          validateExpireIn(expireIn);\n          /* falls through */\n        case \"sum\":\n        case \"min\":\n        case \"max\":\n          type = mutation.type;\n          if (!ObjectHasOwn(mutation, \"value\")) {\n            throw new TypeError(`Invalid mutation '${type}' without value`);\n          }\n          value = serializeValue(mutation.value);\n          break;\n        default:\n          throw new TypeError(\"Invalid mutation type\");\n      }\n      ArrayPrototypePush(this.#mutations, [key, type, value, expireIn]);\n    }\n    return this;\n  }\n\n  sum(key: Deno.KvKey, n: bigint): this {\n    ArrayPrototypePush(this.#mutations, [\n      key,\n      \"sum\",\n      serializeValue(new KvU64(n)),\n      undefined,\n    ]);","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/kv/01_db.ts#L481-L517","documentation":"mutate() requires set/sum/min/max mutations to carry a value as an own property (`ObjectHasOwn(mutation, \"value\")`). Omitting the key entirely throws TypeError(`Invalid mutation '<type>' without value`) naming the offending type. The check is key presence, not value truthiness — but {value: undefined} will fail later during serialization, so always supply a real value.","triggerScenarios":"`kv.atomic().mutate({ type: \"sum\", key })` with no value; object shorthand or destructuring that drops the value field ({type, key} spread from a source without value); conditional mutation building where the value assignment branch was skipped.","commonSituations":"Assuming sum/min/max default to 0 when omitted; porting counter increments from an API where the amount was optional; building mutations via spread from partial records.","solutions":["Always include an explicit value: { type: \"sum\", key, value: 1n }.","Prefer the dedicated helpers .set(key, v), .sum(key, 1n), .min(key, v), .max(key, v) whose signatures force the argument.","Annotate arrays as Deno.KvMutation[] so TypeScript reports the missing value at compile time."],"exampleFix":"// before\nkv.atomic().mutate({ type: \"sum\", key: [\"hits\"] }); // Invalid mutation 'sum' without value\n\n// after\nkv.atomic().mutate({ type: \"sum\", key: [\"hits\"], value: 1n });\n// or simply: kv.atomic().sum([\"hits\"], 1n)","handlingStrategy":"type-guard","validationCode":"for (const m of mutations) {\n  if (m.type !== \"delete\" && !Object.hasOwn(m, \"value\")) {\n    throw new TypeError(`mutation ${m.type} on ${m.key} is missing value`);\n  }\n}","typeGuard":"type FullMutation =\n  | { type: \"delete\"; key: Deno.KvKey }\n  | { type: \"set\" | \"sum\" | \"min\" | \"max\"; key: Deno.KvKey; value: unknown };\n\nconst isFullMutation = (m: FullMutation): boolean =>\n  m.type === \"delete\" || Object.hasOwn(m, \"value\");","tryCatchPattern":null,"preventionTips":["Always emit an explicit value field for set/sum/min/max","Use the dedicated .set()/.sum()/.min()/.max() helpers so arguments are forced","Type mutation arrays as Deno.KvMutation[] and let the compiler catch omissions"],"tags":["deno-kv","atomic","mutate","missing-value","validation"],"backgroundTag":"invalid-mutation","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}