# KV_STORE_NOT_FOUND

<!-- Generated by docs/modules/diagnostics from the package catalogs. Write a guide in docs/diagnostics/<CODE>.md instead of editing this file. -->

An operation on `kv.store(name)` throws `KV_STORE_NOT_FOUND`. The KV config has no store with that name. `error.why` names the store.

## Why it happens

ViteHub reads the store names from the KV config. With `kv.stores`, each key is a store name. With a single store, such as `kv: true` or `kv: { driver: 'fs-lite' }`, the only name is `default`.

`kv.store(name)` does not check the name. The first operation on the handle, such as `get()` or `set()`, looks up the name and throws. The name must match a key of `kv.stores` exactly, with the same case.

The `vitehub kv` commands and the Console report the same code for `--store <name>`. Their message lists the configured stores.

## Fix it

```diff [vite.config.ts]
 export default defineConfig({
   plugins: [vitehub({
     host: 'node',
     kv: {
       stores: {
         default: { driver: 'fs-lite' },
+        sessions: { driver: 'fs-lite', base: '.vitehub/data/kv-sessions' },
       },
     },
   })],
 })
```

Add the store under `kv.stores`. A config with `stores` must also have a `default` store. Restart the dev server after you change the config.

```diff [server/utils/sessions.ts]
-const sessions = kv.store('session')
+const sessions = kv.store('sessions')
```

If the store exists, use its configured name.

## Check the fix

Start the dev server and run `vitehub kv list --store sessions` from another terminal. It lists the keys of the store. A wrong name prints `KV store "<name>" was not found` with the list of stores.

## Related

- [KV configuration](https://vitehub.dev/docs/kv/configure#configuration-options)
- [Use KV at runtime](https://vitehub.dev/docs/kv/server-api#use-it-at-runtime)
- [Read and write KV keys](https://vitehub.dev/docs/development/cli#read-and-write-kv-keys)
- [`KV_DISABLED`](https://vitehub.dev/docs/kv/diagnostics/kv_disabled)
- [`KV_MISSING_DEFAULT_STORE`](https://vitehub.dev/docs/kv/diagnostics/kv_missing_default_store)

## Source

`KV_STORE_NOT_FOUND` belongs to the `kv` package. Its catalog entry is in [`src/error-diagnostics.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/kv/src/error-diagnostics.ts#L155). It is raised in [`src/errors.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/kv/src/errors.ts#L37), [`src/runtime/hosted-storage.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/kv/src/runtime/hosted-storage.ts#L85), [`src/runtime/operations.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/kv/src/runtime/operations.ts#L170).

See [all KV diagnostics](https://vitehub.dev/docs/kv/diagnostics).

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/kv.md)
- [Get started](https://vitehub.dev/raw/docs/kv/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/kv/configure.md)
- [Server API](https://vitehub.dev/raw/docs/kv/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/kv/agent-capability.md)
- [Hosts](https://vitehub.dev/raw/docs/kv/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/kv/limits-and-errors.md)

Next: [KV_CLI_USAGE](https://vitehub.dev/raw/docs/kv/diagnostics/kv_cli_usage.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
