dagger/dagger · error
failed to add vcs generated file: %w
Error message
failed to add vcs generated file: %w
What it means
Thrown by `runCodegen` when appending the updated `.gitattributes` (marking SDK-generated paths as `linguist-generated`) into the generated code directory fails via the `withNewFile` dagql select. The codegen result directory could not be modified.
Source
Thrown at core/schema/modulesource.go:2656
}
fileName := strings.TrimPrefix(fileName, "/")
gitAttrsContents = append(gitAttrsContents,
fmt.Appendf(nil, "/%s linguist-generated\n", fileName)...,
)
}
err = dag.Select(ctx, genDirInst, &genDirInst,
dagql.Selector{
Field: "withNewFile",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(gitAttrsPath)},
{Name: "contents", Value: dagql.String(gitAttrsContents)},
{Name: "permissions", Value: dagql.Int(0o600)},
},
},
)
if err != nil {
return res, fmt.Errorf("failed to add vcs generated file: %w", err)
}
}
// update .gitignore in the generated context directory
writeGitignore := true // default to true if not set
if srcInst.Self().CodegenConfig != nil && srcInst.Self().CodegenConfig.AutomaticGitignore != nil {
writeGitignore = *srcInst.Self().CodegenConfig.AutomaticGitignore
}
vcsIgnoredPaths := generatedCode.VCSIgnoredPaths
if srcInst.Self().ConfigFilename == modules.Filename {
// toml modules build from committed generated files: gitignoring them
// would filter them out of the local module context.
vcsIgnoredPaths = slices.DeleteFunc(slices.Clone(vcsIgnoredPaths), func(ignore string) bool {
return ignoresGeneratedPath(ignore, generatedCode.VCSGeneratedPaths)
})
}
if writeGitignore && len(vcsIgnoredPaths) > 0 {
gitIgnorePath := filepath.Join(srcInst.Self().SourceSubpath, ".gitignore")View on GitHub (pinned to 82ba2681db)
Solutions
- Inspect the wrapped inner error for the concrete dagql/IO failure and fix that.
- Check that no directory conflicts with the `.gitattributes` path inside the module source subpath.
- Validate the SDK's returned VCSGeneratedPaths (no empty/invalid names) if using a custom SDK.
- Retry after restarting the engine if the error indicates transient storage failure.
Example fix
// before: SDK returns generated paths with invalid characters VCSGeneratedPaths: ["sdk/../evil"] // after VCSGeneratedPaths: ["sdk/**"] $ dagger develop
Defensive patterns
Strategy: try-catch
Validate before calling
# ensure no directory occupies the .gitattributes path in the module source ls -la $(grep -q source dagger.json && echo source/ || echo .)/.gitattributes
Try / catch
res, err := s.runCodegen(ctx, srcInst)
if err != nil && strings.Contains(err.Error(), "failed to add vcs generated file") {
return fmt.Errorf("check .gitattributes path conflicts / engine storage: %w", err)
} Prevention
- Don't create a directory named .gitattributes inside the module source subpath.
- For custom SDKs, return clean relative VCSGeneratedPaths entries.
- Restart the engine if directory-mutation errors appear transiently.
When it happens
Trigger: Codegen produced VCSGeneratedPaths and the `withNewFile` select on the generated directory errored — engine-side directory mutation failure, invalid path for the generated file, or an inner dagql error from the select chain.
Common situations: Engine storage/IO failures; path conflicts (e.g. a directory exists where the .gitattributes file should be written); bugs in custom SDKs returning invalid VCSGeneratedPaths entries.
Related errors
- attach generated code directory: unexpected result %T
- apply changes to workspace root: %w
- namespace interface function id: %w
- namespace interface typedef id: %w
- failed to get current dag: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/dfcae7f69d2299de.
Report an issue: GitHub.