GoogleContainerTools/skaffold · error

removing unused default args: %w

Error message

removing unused default args: %w

What it means

Wraps a failure from filterUnusedBuildArgs, which scans the Dockerfile to drop default build args that are not actually used. Failure here means the Dockerfile content could not be scanned/parsed by the filter.

Source

Thrown at pkg/skaffold/docker/build_args.go:79

	for k, v := range defaults {
		result[k] = &v
	}

	for k, v := range extra {
		result[k] = v
	}
	absDockerfilePath, err := NormalizeDockerfilePath(workspace, dockerfilePath)
	if err != nil {
		return nil, fmt.Errorf("normalizing dockerfile path: %w", err)
	}
	f, err := os.Open(absDockerfilePath)
	if err != nil {
		return nil, fmt.Errorf("reading dockerfile: %w", err)
	}
	defer f.Close()
	result, err = filterUnusedBuildArgs(f, result)
	if err != nil {
		return nil, fmt.Errorf("removing unused default args: %w", err)
	}
	for k, v := range args {
		result[k] = v
	}
	result, err = util.EvaluateEnvTemplateMapWithEnv(result, env)
	if err != nil {
		return nil, fmt.Errorf("unable to expand build args: %w", err)
	}
	return result, nil
}

// ArtifactResolver provides an interface to resolve built artifact tags by image name.
type ArtifactResolver interface {
	GetImageTag(imageName string) (string, bool)
}

// ResolveDependencyImages creates a map of artifact aliases to their built image from a required artifacts slice.
// If `missingIsFatal` is false then it is permissive of missing entries in the ArtifactResolver and returns nil for those entries.

View on GitHub (pinned to a1189de023)

Solutions

  1. Read the wrapped inner error to find the parse failure point
  2. Fix Dockerfile syntax around ARG declarations
  3. Re-encode the Dockerfile as UTF-8 without BOM
  4. Retry if the file was mid-write (I/O race)

Example fix

// before
ARG MYARG
MYARG broken line
// after
ARG MYARG
RUN echo $MYARG
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check ARG lines parse as UTF-8 text with valid syntax
b, err := os.ReadFile(absDockerfilePath)
if err != nil { return err }
if !utf8.Valid(b) { return fmt.Errorf("dockerfile is not valid UTF-8") }

Try / catch

args, err := evalBuildArgs(workspace, df, args, env)
if err != nil && strings.Contains(err.Error(), "removing unused default args") {
  return fmt.Errorf("Dockerfile could not be scanned; check syntax near ARG lines: %w", err)
}

Prevention

When it happens

Trigger: evalBuildArgs calls filterUnusedBuildArgs(f, result) after opening the Dockerfile; the scanner errors, e.g. on a read error or Dockerfile syntax it cannot parse (malformed ARG/ONBUILD lines).

Common situations: Dockerfile with unusual constructs or encoding issues; I/O error reading a partially-written file; unexpected parser version behavior.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/b7a5b475dc4a58de. Report an issue: GitHub.