pulumi/pulumi · error

reading environment definition: %w

Error message

reading environment definition: %w

What it means

When `esc env edit --file` is given a file ('-' for stdin or a filesystem path), this wraps any error from reading that file's YAML bytes. It indicates the environment definition could not be loaded before being validated/applied.

Source

Thrown at pkg/cmd/esc/cli/env_edit.go:86

			ref, args, err := edit.env.getExistingEnvRef(ctx, args)
			if err != nil {
				return err
			}
			if ref.version != "" {
				return errors.New("the edit command does not accept versions")
			}
			_ = args

			if file != "" {
				var yaml []byte
				switch file {
				case "-":
					yaml, err = io.ReadAll(env.esc.stdin)
				default:
					yaml, err = fs.ReadFile(env.esc.fs, file)
				}
				if err != nil {
					return fmt.Errorf("reading environment definition: %w", err)
				}

				diags, err := edit.env.esc.updateEnvironment(ctx, ref, draft, yaml, "", "Environment updated.")
				if err != nil {
					return err
				}

				if len(diags) != 0 {
					err = edit.env.writeYAMLEnvironmentDiagnostics(
						edit.env.esc.stderr,
						ref.projectName+"/"+ref.envName,
						yaml,
						diags,
					)
					contract.IgnoreError(err)
				}
				if client.DiagnosticsHaveErrors(diags) {
					return err

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Check the file path is correct relative to the current directory
  2. Verify read permissions on the file (ls -l, chmod if needed)
  3. If using '-', ensure stdin actually contains the YAML (check the upstream command/redirect)
  4. Read the wrapped cause (%w) — for fs.PathError it names the exact path and reason

Example fix

// before
esc env edit --file enviroment.yaml   # typo
// after
esc env edit --file environment.yaml
Defensive patterns

Strategy: try-catch

Validate before calling

if file != "" && file != "-" {
    if _, err := os.Stat(file); err != nil {
        return fmt.Errorf("file %q not readable: %w", file, err)
    }
}

Try / catch

yaml, err := fs.ReadFile(env.esc.fs, file)
if err != nil {
    var perr *fs.PathError
    if errors.As(err, &perr) {
        return fmt.Errorf("cannot read %s: %v", perr.Path, perr.Err)
    }
    return fmt.Errorf("reading environment definition: %w", err)
}

Prevention

When it happens

Trigger: Running `esc env edit --file config.yaml` where config.yaml does not exist, is unreadable (permissions), or stdin ('-') fails/closes; also `esc env edit - < missing-input`.

Common situations: Typo in the filename or wrong working directory; file created by a prior pipeline step that failed; redirecting stdin in a script where the producer failed; permission-restricted files.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/a06d0c0bf35cc7b4. Report an issue: GitHub.