cilium/cilium · error
failed to open original source file for conversion: %w
Error message
failed to open original source file for conversion: %w
What it means
After rewriting the copyright/SPDX comment lines in the parsed AST, conv opens the original source file with os.OpenFile(path, os.O_TRUNC|os.O_RDWR, 0660) to rewrite it in place. If the file cannot be opened — missing permissions, read-only filesystem, or the file vanished between parsing and opening — this wrapped error is returned.
Source
Thrown at tools/spdxconv/main.go:102
}
var spdx string
for exp, tmp := range RegexpMap {
if exp.MatchString(cg.Text()) {
spdx = tmp
}
}
if spdx == "" {
log.Printf("could not determine license for %v", path)
return nil
}
copyRight := cg.List[0].Text
cg.List[0].Text, cg.List[1].Text = spdx, copyRight
cg.List = cg.List[:2]
fd, err := os.OpenFile(path, os.O_TRUNC|os.O_RDWR, 0660)
if err != nil {
return fmt.Errorf("failed to open original source file for conversion: %w", err)
}
defer fd.Close()
err = format.Node(fd, fset, f)
if err != nil {
return fmt.Errorf("failed to write converted file %v: %w", path, err)
}
return nil
}
func main() {
switch {
case len(os.Args) != 2:
fmt.Print(usage)
os.Exit(1)
case os.Args[1] == "help":
fmt.Print(usage)View on GitHub (pinned to ac7b90affa)
Solutions
- Check and fix file permissions: chmod u+w <file> or run the tool as the file owner.
- Ensure the filesystem/mount is writable (remount rw, drop the read-only flag in CI).
- Verify the file still exists; re-run the tool on a clean checkout.
Example fix
// before chmod 444 pkg/foo.go && spdxconv ./pkg // after chmod 644 pkg/foo.go && spdxconv ./pkg
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(path)
if err != nil || !info.Mode().IsRegular() {
return fmt.Errorf("%s not a writable regular file", path)
}
if f, err := os.OpenFile(path, os.O_WRONLY, 0); err != nil { return err } else { f.Close() } Try / catch
if err := conv(path, fset, f); err != nil {
if errors.Is(err, fs.ErrPermission) {
// escalate or skip file
}
return err
} Prevention
- Run the tool as a user with write access to all target files.
- Ensure the workspace mount is read-write (CI checkout, container volumes).
- Stat paths before conversion to confirm they are regular writable files.
When it happens
Trigger: os.OpenFile fails on the target .go file: no write permission (non-root running against files owned by another user), the file was deleted after parsing, a device/permission mismatch, or O_TRUNC on a path that is not a regular file.
Common situations: Running spdxconv in CI as a non-privileged user against a checked-out tree with restricted permissions; read-only container mounts; converting files under /proc or similar pseudo-filesystems.
Related errors
- Failed to open file %s for writing: %w
- reading health history directory: %w
- failed to create plugin path %s: %w
- unable to create cilium sysctl overwrites config: %w
- Cannot write config: %w
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/5cf2d51c673708eb.
Report an issue: GitHub.