tobi/qmd · error · Error

resolve: at least one path segment is required

Error message

resolve: at least one path segment is required

What it means

The store's custom resolve() helper requires at least one path segment. It is a path.join/posix-resolve replacement used throughout store.ts (resolveGrammarPath, allScores, raw, cacheDir, mcpDaemonPaths, flushWritable) and throws immediately when called with zero arguments.

Source

Thrown at src/store.ts:532

    ? normalizedPrefix + '/' 
    : normalizedPrefix;
  
  // Exact match
  if (normalizedPath === normalizedPrefix) {
    return '';
  }
  
  // Check if path starts with prefix
  if (normalizedPath.startsWith(prefixWithSlash)) {
    return normalizedPath.slice(prefixWithSlash.length);
  }
  
  return null;
}

export function resolve(...paths: string[]): string {
  if (paths.length === 0) {
    throw new Error("resolve: at least one path segment is required");
  }
  
  // Normalize all paths to use forward slashes
  const normalizedPaths = paths.map(normalizePathSeparators);
  
  let result = '';
  let windowsDrive = '';
  
  // Check if first path is absolute
  const firstPath = normalizedPaths[0]!;
  if (isAbsolutePath(firstPath)) {
    result = firstPath;
    
    // Extract Windows drive letter if present
    if (firstPath.length >= 2 && /[a-zA-Z]/.test(firstPath[0]!) && firstPath[1] === ':') {
      windowsDrive = firstPath.slice(0, 2);
      result = firstPath.slice(2);
    } else if (!isWSL() && firstPath.startsWith('/') && firstPath.length >= 3 && firstPath[2] === '/') {

View on GitHub (pinned to dbfd0b4736)

Solutions

  1. Default the segments: resolve(...(segments.length ? segments : ['.']))
  2. Fix the caller to always pass a root segment (e.g. cacheDir or homedir())
  3. Guard with an if before calling resolve when the array may be empty

Example fix

// before
const p = resolve(...parts); // throws when parts is []
// after
const p = resolve(...(parts.length ? parts : ['.']));
Defensive patterns

Strategy: validation

Validate before calling

if (segments.length === 0) throw new TypeError('segments required'); const p = resolve(...segments);

Type guard

const hasSegments = (s: unknown[]) => s.length > 0;

Prevention

When it happens

Trigger: Calling resolve() with no arguments, or with a spread of an empty array — e.g. resolve(...segments) where segments was empty after filtering.

Common situations: Dynamic path building where an optional base/segments list turns out empty (missing config, empty path arrays); refactors that changed a caller to conditionally pass segments; passing undefined then spreading nothing.

Related errors


AI-assisted analysis of tobi/qmd@dbfd0b4736 (2026-08-28). Data as JSON: /api/errors/d76526530b57b20d. Report an issue: GitHub.