{"record":{"id":"72d5e0982848458a","repo":"denoland/deno","slug":"selector-can-not-specify-both-start-and-end-ke","errorCode":null,"errorMessage":"Selector can not specify both 'start' and 'end' key when specifying 'prefix'","messagePattern":"Selector can not specify both 'start' and 'end' key when specifying 'prefix'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/kv/01_db.ts","lineNumber":873,"sourceCode":"      ) => Promise<Deno.KvEntry<unknown>[]>;\n    },\n  ) {\n    super();\n    let prefix: Deno.KvKey | undefined;\n    let start: Deno.KvKey | undefined;\n    let end: Deno.KvKey | undefined;\n    if (ObjectHasOwn(selector, \"prefix\") && selector.prefix !== undefined) {\n      prefix = ObjectFreeze(ArrayPrototypeSlice(selector.prefix));\n    }\n    if (ObjectHasOwn(selector, \"start\") && selector.start !== undefined) {\n      start = ObjectFreeze(ArrayPrototypeSlice(selector.start));\n    }\n    if (ObjectHasOwn(selector, \"end\") && selector.end !== undefined) {\n      end = ObjectFreeze(ArrayPrototypeSlice(selector.end));\n    }\n    if (prefix) {\n      if (start && end) {\n        throw new TypeError(\n          \"Selector can not specify both 'start' and 'end' key when specifying 'prefix'\",\n        );\n      }\n      if (start) {\n        this.#selector = { prefix, start };\n      } else if (end) {\n        this.#selector = { prefix, end };\n      } else {\n        this.#selector = { prefix };\n      }\n    } else {\n      if (start && end) {\n        this.#selector = { start, end };\n      } else {\n        throw new TypeError(\n          \"Selector must specify either 'prefix' or both 'start' and 'end' key\",\n        );\n      }","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/kv/01_db.ts#L855-L891","documentation":"A Kv list selector may combine prefix with at most one range bound: {prefix, start?} or {prefix, end?}. Specifying prefix together with both start and end throws TypeError(\"Selector can not specify both 'start' and 'end' key when specifying 'prefix'\") — the prefix already fixes the bounds of the range, so a third constraint is contradictory.","triggerScenarios":"`kv.list({ prefix: [\"users\"], start: [\"users\", \"a\"], end: [\"users\", \"z\"] })` — selectors assembled generically from whatever fields are present, or migrated from a {start, end} selector to prefix without removing the old bounds.","commonSituations":"Generic query builders attaching every provided option; config objects reused across queries; refactors that add a prefix for scoping but leave legacy bounds in place.","solutions":["Drop the prefix and keep { start, end } when you need an explicit range.","Keep the prefix with exactly one bound: { prefix, end } pages up to a boundary; { prefix, start } pages from one.","Build selectors through a helper that enforces at most one bound alongside prefix."],"exampleFix":"// before\nkv.list({ prefix: [\"users\"], start: [\"users\", \"a\"], end: [\"users\", \"z\"] });\n\n// after\nkv.list({ start: [\"users\", \"a\"], end: [\"users\", \"z\"] });\n// or, if scoping to the prefix is what you want:\nkv.list({ prefix: [\"users\"], end: [\"users\", \"z\"] });","handlingStrategy":"validation","validationCode":"function makeSelector(s: Record<string, unknown>) {\n  const has = (k: string) => Object.hasOwn(s, k) && s[k] !== undefined;\n  if (has(\"prefix\") && has(\"start\") && has(\"end\")) {\n    const { start, end, ...rest } = s; // drop prefix instead: full range wins\n    return { start, end };\n  }\n  return s;\n}\nkv.list(makeSelector(rawSelector));","typeGuard":"type SafeSelector =\n  | { prefix: Deno.KvKey; start?: Deno.KvKey }\n  | { prefix: Deno.KvKey; end?: Deno.KvKey }\n  | { start: Deno.KvKey; end: Deno.KvKey };\n\nconst isSafeSelector = (s: SafeSelector): boolean =>\n  !(\"prefix\" in s && \"start\" in s && \"end\" in s);","tryCatchPattern":null,"preventionTips":["Never attach both start and end alongside prefix","Scope tenant/datacenter subsets with prefix + at most one bound","Centralize selector construction in one validated helper"],"tags":["deno-kv","kv-list","selector","prefix","range"],"backgroundTag":"invalid-range-selector","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"}