dagger/dagger · error

failed to get git attributes file contents: %w

Error message

failed to get git attributes file contents: %w

What it means

Thrown by `runCodegen` when reading the contents of the module's existing `.gitattributes` file fails. After codegen produces VCS-generated paths, Dagger reads the existing .gitattributes (if present) to append `linguist-generated` entries; a failure to read contents aborts codegen.

Source

Thrown at core/schema/modulesource.go:2627

	}
	genDirInst := generatedCode.Code

	// update .gitattributes in the generated context directory
	if len(generatedCode.VCSGeneratedPaths) > 0 {
		gitAttrsPath := filepath.Join(srcInst.Self().SourceSubpath, ".gitattributes")
		var gitAttrsContents []byte
		var gitAttrsFile dagql.ObjectResult[*core.File]
		err = dag.Select(ctx, srcInst.Self().ContextDirectory, &gitAttrsFile, dagql.Selector{
			Field: "file",
			Args: []dagql.NamedInput{
				{Name: "path", Value: dagql.String(gitAttrsPath)},
			},
		})
		if err == nil {
			var contents dagql.String
			err = dag.Select(ctx, gitAttrsFile, &contents, dagql.Selector{Field: "contents"})
			if err != nil {
				return res, fmt.Errorf("failed to get git attributes file contents: %w", err)
			}
			gitAttrsContents = []byte(contents)
			if !bytes.HasSuffix(gitAttrsContents, []byte("\n")) {
				gitAttrsContents = append(gitAttrsContents, []byte("\n")...)
			}
		}
		for _, fileName := range generatedCode.VCSGeneratedPaths {
			if bytes.Contains(gitAttrsContents, []byte(fileName)) {
				// already has some config for the file
				continue
			}
			fileName := strings.TrimPrefix(fileName, "/")
			gitAttrsContents = append(gitAttrsContents,
				fmt.Appendf(nil, "/%s linguist-generated\n", fileName)...,
			)
		}

		err = dag.Select(ctx, genDirInst, &genDirInst,

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Retry the codegen operation (often transient storage/IO).
  2. If persistent, check engine state/store health — restart the engine or clear the local Dagger data dir if blobs are corrupted.
  3. Verify the `.gitattributes` in the module context is a normal readable text file and re-run `dagger develop`.

Example fix

# before: transient failure during dagger develop
$ dagger develop  # failed to get git attributes file contents
# after: retry / reset engine store
$ dagger develop  # succeeds
Defensive patterns

Strategy: retry

Validate before calling

# ensure the context directory's .gitattributes is a plain readable file
file .gitattributes && head .gitattributes

Try / catch

res, err := s.runCodegen(ctx, srcInst)
if err != nil && strings.Contains(err.Error(), "failed to get git attributes file contents") {
    // transient storage error: retry once, then inspect engine store
    return s.runCodegen(ctx, srcInst)
}

Prevention

When it happens

Trigger: The context directory's `.gitattributes` exists (the `file` select succeeded) but reading its `contents` fails — typically an engine-side blob/storage error, or a race where the file was removed between the existence check and the content read.

Common situations: Corrupt or unreadable file blobs in the engine content store; transient engine/LLM-cache storage errors; concurrent modification of the context directory during codegen.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/e4d89fcece15269f. Report an issue: GitHub.