GoogleContainerTools/skaffold · error
failed to analyze file %s: %s
Error message
failed to analyze file %s: %s
What it means
During `skaffold init` analysis, the config analyzer skips files it doesn't need, but for a file that looks like a skaffold config it calls sameFiles(filePath, a.targetConfig) to detect whether it duplicates the target config. If that comparison fails (typically an unreadable file or I/O error), the error is wrapped as 'failed to analyze file %s'. If the files match, a PreExistingConfigErr is returned instead.
Source
Thrown at pkg/skaffold/initializer/analyze/config.go:41
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/initializer/errors"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema"
)
type skaffoldConfigAnalyzer struct {
directoryAnalyzer
force bool
analyzeMode bool
targetConfig string
}
func (a *skaffoldConfigAnalyzer) analyzeFile(ctx context.Context, filePath string) error {
if !schema.IsSkaffoldConfig(filePath) || a.force || a.analyzeMode {
return nil
}
sameFiles, err := sameFiles(filePath, a.targetConfig)
if err != nil {
return fmt.Errorf("failed to analyze file %s: %s", filePath, err)
}
if !sameFiles {
return nil
}
return errors.PreExistingConfigErr{Path: filePath}
}
func sameFiles(a, b string) (bool, error) {
absA, err := filepath.Abs(a)
if err != nil {
return false, err
}
absB, err := filepath.Abs(b)
if err != nil {
return false, err
}
return absA == absB, nilView on GitHub (pinned to a1189de023)
Solutions
- Fix file permissions on the existing skaffold config (chmod u+r) so it can be read
- Remove/repair broken symlinks pointing at configs
- Inspect the wrapped error (%s) for the exact OS failure and address it
- Run init with --force to bypass config-analysis checks if you intend to overwrite configs
Example fix
// shell # before ls -l skaffold.yaml # -rw------- root root # after chmod 644 skaffold.yaml skaffold init
Defensive patterns
Strategy: validation
Validate before calling
// before running init, ensure existing configs are readable:
for _, f := range existingConfigs {
if info, err := os.Stat(f); err != nil || info.IsDir() {
return fmt.Errorf("config %s unreadable or a directory", f)
}
fh, err := os.Open(f)
if err != nil { return fmt.Errorf("cannot read %s: %w", f, err) }
fh.Close()
} Try / catch
if _, err := os.Stat("skaffold.yaml"); err == nil {
if err := os.Chmod("skaffold.yaml", 0o644); err != nil {
return fmt.Errorf("fix permissions before init: %w", err)
}
} Prevention
- Keep skaffold configs world-readable (0644) in shared repos
- Avoid symlinks for configs, or ensure targets exist
- Don't run init in read-only or foreign-ownership directories
When it happens
Trigger: Running skaffold init in a directory containing an existing skaffold.yaml whose contents cannot be compared to the target config because sameFiles fails — e.g. permission denied reading the file, the file is a broken symlink, or an OS-level read error.
Common situations: skaffold.yaml with restrictive permissions (read as non-root); file owned by another user; broken symlink to a config; running init inside a container with a read-only or oddly-mounted volume.
Related errors
- writing %q to %q: %w
- reading .dockerignore: %w
- walking workspace: %w
- unable to stat file %q: %w
- failed to create directory: %v
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/6dcba94ae8b8b614.
Report an issue: GitHub.