hcengineering/platform · error
Invalid key
Error message
Invalid key
What it means
Error thrown by PreviewCache.put when the supplied cache key is an empty string. Empty keys cannot map to a stable file path under the cache directory, so the write is rejected early before touching the filesystem.
Source
Thrown at pods/preview/src/cache.ts:140
this.ctx.error('Failed to remove cache file', { path: entry, error: err })
}
})
return Promise.all(promises)
},
{ cacheCount: this.cache.size, cacheSize: this.cache.calculatedSize, gcCount: disposed.length }
)
}
get (key: string): PreviewFile | undefined {
return this.cache.get(key)
}
async put (key: string, value: PreviewFile): Promise<PreviewFile> {
let filePath = normalize(value.filePath)
if (key.length === 0) {
throw new Error('Invalid key')
}
const { size } = await stat(value.filePath)
if (!filePath.startsWith(this.cachePath)) {
try {
filePath = this.getFilePath(key)
await mkdir(dirname(filePath), { recursive: true })
await rename(value.filePath, filePath)
} catch (err) {
this.ctx.error('Failed to move file to cache', { filePath, error: err })
throw err
}
}
const entry = { ...value, filePath, size }
this.cache.set(key, entry)
View on GitHub (pinned to 63e28dc964)
Solutions
- Validate the key before calling put: if (!key) throw or skip the cache write
- Fix upstream key derivation so it always yields a non-empty digest (check what is being hashed)
- Guard put() at the call site and fall back to a no-cache path
- Log the input that produced the empty key to trace the derivation bug
Example fix
// before
await cache.put(key, previewFile) // key === ''
// after
if (!key) {
console.warn('skip cache: empty key for', sourceUrl)
} else {
await cache.put(key, previewFile)
} Defensive patterns
Strategy: validation
Validate before calling
if (typeof key !== 'string' || key.length === 0) throw new Error('cache key required') Try / catch
try {
await cache.put(key, value)
} catch (e) {
if (e.message === 'Invalid key') return null // bypass cache
throw e
} Prevention
- Validate keys before every cache operation
- Ensure hash functions cannot return empty output
- Trace empty-key sources (untrimmed URL fields, unset variables)
- Treat empty keys as cache bypass, not a crash
When it happens
Trigger: Calling cache.put('', file) — typically because the hash/key derivation returned '' (e.g. hashing an empty URL, a failed digest, or a variable defaulting to empty before the call).
Common situations: Hash function silently returning empty on invalid input, using an unescaped/trimmed URL field that ends up empty, or wiring bugs where the key variable was never populated.
Related errors
- Key cannot be empty
- Failed to load server config
- getDisplayMedia not supported
- No screen access granted
- Message id is required
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/6dc914949ff7521b.
Report an issue: GitHub.