dagger/dagger · error
failed to check outer env file type at %q: %w
Error message
failed to check outer env file type at %q: %w
What it means
This error wraps a failure while probing whether the outer .env file (e.g. `<module-root>/.env`) exists and is a regular file, during loading of environment files for a Dagger module source. The existence check itself is a dagql call (`dag.Select` on a Directory `file` field with `expectedType: ExistsTypeRegular`), and any error returned by that field is wrapped with the offending path. Dagger wraps it so the developer can see exactly which env-file path could not be stat'ed.
Source
Thrown at core/modulesource.go:1304
var isRegularFile bool
if err := dag.Select(ctx, dag.Root(), &isRegularFile,
dagql.Selector{Field: "host"},
dagql.Selector{
Field: "directory",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(envFileDir)},
{Name: "include", Value: dagql.ArrayInput[dagql.String]{dagql.String(envFileName)}},
},
},
dagql.Selector{
Field: "exists",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(envFileName)},
{Name: "expectedType", Value: dagql.Opt(ExistsTypeRegular)},
},
},
); err != nil {
return nil, "", fmt.Errorf("failed to check outer env file type at %q: %w", envFilePath.String(), err)
}
if !isRegularFile {
return &EnvFile{}, "", nil
}
var envFile *EnvFile
if err := dag.Select(ctx, dag.Root(), &envFile,
dagql.Selector{Field: "host"},
dagql.Selector{
Field: "file",
Args: []dagql.NamedInput{
{Name: "path", Value: envFilePath},
},
},
dagql.Selector{
Field: "asEnvFile",
Args: []dagql.NamedInput{
{Name: "expand", Value: dagql.Opt(dagql.NewBoolean(true))},
},View on GitHub (pinned to 82ba2681db)
Solutions
- Verify the path exists and is readable on the caller's host; re-run `dagger develop` or re-sync the module source
- Ensure you are inside a module call context (the code requires CurrentDagqlServer/CurrentQuery to work); don't invoke this path from a bare context
- Re-create the .env file or remove it if not needed — the code treats a missing regular file as an empty EnvFile, so only probe errors are fatal
- Update Dagger CLI/engine; this area of modulesource.go has been actively reworked
Example fix
// before: calling env loading with a stale/renamed module root
mod.LoadUserDefaults(ctx)
// after: ensure the source root still contains the file before loading
if _, err := os.Stat(filepath.Join(moduleRoot, ".env")); err != nil {
log.Printf("no outer .env, skipping: %v", err)
} else {
mod.LoadUserDefaults(ctx)
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go: probe the file before triggering env-file loading
if _, err := os.Stat(filepath.Join(moduleRoot, ".env")); err != nil {
if os.IsNotExist(err) { /* skip outer env file */ }
} Type guard
func envFileAccessible(root string) bool {
fi, err := os.Stat(filepath.Join(root, ".env"))
return err == nil && !fi.IsDir()
} Try / catch
envFile, _, err := loadOuterEnvFile(ctx, src)
if err != nil {
if strings.Contains(err.Error(), "failed to check outer env file type") {
log.Printf("outer env file unavailable, continuing with defaults: %v", err)
envFile = &EnvFile{}
} else {
return err
}
} Prevention
- Verify the module source root is synced and readable before calls
- Keep .env a regular file, not a symlink or directory
- Keep CLI/engine versions in sync
When it happens
Trigger: Calling module source loading / env file loading (innerEnvFile / outer env handling in ModuleSource, e.g. ModuleSource.LoadUserDefaults paths) when the directory containing the .env file cannot be resolved by the dagql server — typically because the client filesystem metadata is wrong (module running without proper caller client metadata) or the context directory is unavailable.
Common situations: Running a module function whose source directory was deleted or remounted mid-call; using a git/remote module source whose env file path is not materialized locally; stale client metadata after NonModuleParentClientMetadata changes.
Related errors
- failed to load outer env file from %q: %s
- workspace config detection: %w
- workspace config directory: %w
- workspace lock detection: %w
- workspace lock directory: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/b59b0420ecd96bc4.
Report an issue: GitHub.