kubernetes/kops · warning

error finding relative path for %q: %v

Error message

error finding relative path for %q: %v

What it means

For every regular file found in the extracted tree, addArchive computes its path relative to localBase with filepath.Rel to build the asset key. filepath.Rel fails (an ErrBadPair-style error) only when the two paths cannot be made relative — practically impossible when localPath comes from the same walk — so this indicates an internal invariant violation or a corrupted localBase (e.g. non-absolute/relative mismatch).

Source

Thrown at upup/pkg/fi/assetstore.go:337

			return fmt.Errorf("error renaming extracted temp dir %s -> %s: %v", extractedTemp, extracted, err)
		}
	}

	localBase := extracted
	assetBase := ""

	walker := func(localPath string, info os.FileInfo, err error) error {
		if err != nil {
			return fmt.Errorf("error descending into path %q: %v", localPath, err)
		}

		if info.IsDir() {
			return nil
		}

		relativePath, err := filepath.Rel(localBase, localPath)
		if err != nil {
			return fmt.Errorf("error finding relative path for %q: %v", localPath, err)
		}

		assetPath := path.Join(assetBase, relativePath)
		key := info.Name()
		r := NewFileResource(localPath)

		asset := &asset{
			Key:       key,
			AssetPath: assetPath,
			resource:  r,
			source:    &Source{Parent: archiveSource, ExtractFromArchive: assetPath},
		}
		klog.V(2).Infof("added asset %q for %q", asset.Key, asset.resource)
		a.assets = append(a.assets, asset)

		return nil
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Report as a bug: capture localBase and localPath from the message.
  2. Verify the kOps version and check for related fixed issues in the changelog.
  3. Work around by re-running; this error is deterministic, so escalate to maintainers if reproducible.
Defensive patterns

Strategy: fallback

Validate before calling

import path from "path" // sanity-check base/path relationship the way filepath.Rel requires
function canBeRelative(base: string, target: string): boolean {
  const rBase = path.resolve(base), rTarget = path.resolve(target)
  return rTarget === rBase || rTarget.startsWith(rBase + path.sep)
}

Try / catch

try {
  await addURLs(urls)
} catch (e) {
  if (/error finding relative path for/.test(e.message)) {
    // internal invariant violation — capture message and report a bug
    console.error("BUG: report with this message:", e.message)
  }
  throw e
}

Prevention

When it happens

Trigger: filepath.Walk callback in addArchive: filepath.Rel(localBase, localPath) returns error because localBase is not a prefix-compatible base for localPath — only via programming/config error, not from normal user input.

Common situations: Effectively never hit by end users; would appear if the extraction root constant changed or path handling was refactored to mix relative and absolute paths.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/d05b7e7ef74b1a78. Report an issue: GitHub.