NoriKV TypeScript Client Troubleshooting Guide¶
Solutions to common issues when using the TypeScript/JavaScript client SDK.
Connection Issues¶
"Connection refused" or ECONNREFUSED¶
Symptoms:
Solutions:
-
Verify server is running:
-
Check client configuration:
-
Test connectivity:
"Deadline exceeded" or timeout errors¶
Symptoms:
Solutions:
-
Increase timeout:
-
Enable retries:
Performance Problems¶
Slow operations¶
Diagnosis:
Solutions:
-
Use appropriate consistency level:
-
Batch operations:
-
Check value sizes:
High memory usage¶
Solutions:
-
Close client when done:
-
Clean up topology listeners:
-
Use Node.js profiling:
Version Conflicts¶
Frequent VersionMismatchError¶
Symptoms:
Solution - Implement retry loop:
async function casWithRetry(
key: string,
transform: (value: string) => string,
maxRetries: number = 10
): Promise<void> {
for (let i = 0; i < maxRetries; i++) {
try {
const result = await client.get(key);
const newValue = transform(bytesToString(result.value));
await client.put(key, newValue, {
ifMatchVersion: result.version,
});
return; // Success
} catch (err) {
if (!(err instanceof VersionMismatchError)) {
throw err;
}
if (i === maxRetries - 1) {
throw new Error('CAS failed after retries');
}
// Exponential backoff
await new Promise(r => setTimeout(r, Math.pow(2, i) * 10));
}
}
}
Error Messages¶
"Key not found"¶
Handling:
try {
const result = await client.get(key);
} catch (err) {
if (err instanceof KeyNotFoundError) {
// Use default value or create key
return defaultValue;
}
throw err;
}
"Version mismatch"¶
Handling: See Version Conflicts above.
"Connection error"¶
Handling:
async function withRetry<T>(
operation: () => Promise<T>
): Promise<T> {
const maxAttempts = 3;
for (let i = 0; i < maxAttempts; i++) {
try {
return await operation();
} catch (err) {
if (!(err instanceof ConnectionError) || i === maxAttempts - 1) {
throw err;
}
await new Promise(r => setTimeout(r, Math.pow(2, i) * 100));
}
}
throw new Error('Unreachable');
}
TypeScript-Specific Issues¶
Type errors with buffers¶
Problem:
Solution:
import { stringToBytes } from '@norikv/client';
const value = stringToBytes('hello'); // Uint8Array
await client.put(key, value);
Async/await not working¶
Problem:
Solution:
Module resolution errors¶
Problem:
Solution:
-
Install package:
-
Check tsconfig.json:
Browser Issues¶
"Buffer is not defined"¶
Solution - Add buffer polyfill:
gRPC not working in browser¶
Solution - Use gRPC-Web:
import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';
// Configure client for browser
const transport = new GrpcWebFetchTransport({
baseUrl: 'http://localhost:8080'
});
Common Pitfalls¶
1. Not awaiting promises¶
2. Creating client per request¶
// Bad
async function handleRequest() {
const client = new NoriKVClient(config);
await client.connect();
await client.put(key, value);
await client.close(); // Expensive!
}
// Good
const client = new NoriKVClient(config);
await client.connect();
// Reuse client across requests
3. Not handling errors¶
// Bad
const result = await client.get(key); // May throw
// Good
try {
const result = await client.get(key);
} catch (err) {
if (err instanceof KeyNotFoundError) {
return null;
}
throw err;
}
4. Mixing callbacks and async/await¶
// Bad
client.put(key, value).then(() => {
client.get(key).then(result => {
console.log(result);
});
});
// Good
const version = await client.put(key, value);
const result = await client.get(key);
console.log(result);
Debugging Tips¶
Enable debug logging¶
Use Node.js debugger¶
Monitor operations¶
const start = Date.now();
await client.put(key, value);
console.log(`PUT took ${Date.now() - start}ms`);
Check client stats¶
Getting Help¶
- Issues: GitHub Issues
- Documentation: API Guide, Architecture Guide
- Examples: GitHub Examples