cilium/cilium · error

opening %s: %w

Error message

opening %s: %w

What it means

After writing the BTF blob, runMaps creates maps_generated.go with os.Create to hold rendered MapSpec Go code. This error wraps the os.Create failure for that output file, meaning the generator cannot produce the Go source file.

Source

Thrown at tools/dpgen/maps.go:114

					return err
				}
			}
		}

		objsDone.Insert(objName)
	}

	btfBlob, err := marshalSorted(bb)
	if err != nil {
		return fmt.Errorf("marshaling combined BTF: %w", err)
	}
	if err := os.WriteFile(mapKVFile, btfBlob, 0644); err != nil {
		return fmt.Errorf("writing %s: %w", mapKVFile, err)
	}

	f, err := os.Create(mapsGoFile)
	if err != nil {
		return fmt.Errorf("opening %s: %w", mapsGoFile, err)
	}
	defer f.Close()

	if err := renderMapSpecs(f, outer, inner, mapsOpts.goPkg); err != nil {
		return fmt.Errorf("rendering MapSpecs: %w", err)
	}

	f, err = os.Create(mapsGoTestFile)
	if err != nil {
		return fmt.Errorf("opening %s: %w", mapsGoTestFile, err)
	}
	defer f.Close()

	if err := renderMapSpecsTest(f, mapsOpts.goPkg); err != nil {
		return fmt.Errorf("rendering MapSpecs test: %w", err)
	}

	return nil

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Check the wrapped OS error and fix permissions on maps_generated.go (e.g. chmod u+w) or delete it
  2. Ensure the process runs as a user with write access to the target directory
  3. Verify the working directory is writable before running the dpgen maps command

Example fix

// before
-r--r--r-- maps_generated.go
// after
$ chmod u+w maps_generated.go && dpgen maps datapath/bpf/*.o
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(mapsGoFile); err == nil && info.Mode().Perm()&0200 == 0 {
	return fmt.Errorf("%s is not writable; run chmod u+w %s", mapsGoFile, mapsGoFile)
}

Try / catch

if err := runMaps(cmd, args); err != nil {
	var pe *fs.PathError
	if errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {
		log.Fatalf("fix permissions on %s before regenerating", pe.Path)
	}
	return err
}

Prevention

When it happens

Trigger: os.Create(mapsGoFile) fails: maps_generated.go exists with read-only permissions, the directory is not writable, or the path is a directory.

Common situations: A previously generated maps_generated.go was checked in or chowned by root and is now read-only; running the generator as a different (unprivileged) user in CI; running from a read-only mounted directory.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/b98079c21cd4840b. Report an issue: GitHub.