hcengineering/platform · error

Key cannot be empty

Error message

Key cannot be empty

What it means

Error thrown by the private getFilePath helper when given an empty key. getFilePath is called by put (and other operations) to convert a key into a filesystem path; empty keys are rejected before path construction.

Source

Thrown at pods/preview/src/cache.ts:168

      } 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)

    return entry
  }

  async delete (key: string): Promise<void> {
    this.cache.delete(key)
  }

  private getFilePath (key: string): string {
    if (key.length === 0) {
      throw new Error('Key cannot be empty')
    }

    if (key.includes('..') || key.includes('./') || key.includes('/.')) {
      throw new Error('Key contains invalid path sequences')
    }

    key = key.replace(/[^a-zA-Z0-9-_/]/g, '_')
    const path = join(this.cachePath, key)

    if (!this.isPathWithinCache(path)) {
      throw new Error('Cache path is outside of cache directory')
    }

    return path
  }

  private isPathWithinCache (filePath: string): boolean {
    const normalizedPath = resolve(normalize(filePath))

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure keys are non-empty before any cache operation (validate at the API boundary)
  2. Fix the key-generation function to reject/repair empty inputs
  3. Cache-miss behavior: treat empty key as a cache bypass rather than an error if acceptable
  4. Trace with a breakpoint/log on getFilePath to find who supplies the empty key

Example fix

// before
const path = cache.getFilePath(key) // throws if key === ''
// after
const path = key ? cache.getFilePath(key) : null
if (path) { /* use cached file */ }
Defensive patterns

Strategy: validation

Validate before calling

if (typeof key !== 'string' || key.length === 0) return null

Try / catch

try {
  await cache.put(key, value)
} catch (e) {
  if (e.message === 'Key cannot be empty') return null
  throw e
}

Prevention

When it happens

Trigger: cache.put('', value) or other cache operations passing '' internally, mirroring error 466's empty-key condition at the path-resolution layer.

Common situations: Same root causes as 'Invalid key': empty hash results, unset key variables, or upstream data loss where the URL/identifier used as key was blank.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/77fa6b0500524443. Report an issue: GitHub.