opentofu/opentofu · error

error marshaling config: %w

Error message

error marshaling config: %w

What it means

Final stage wrapper: jsonconfig.Marshal failed while embedding the configuration view into the JSON plan. The inner error is one of the config-marshal failures - type-constraint marshaling (unreachable-by-design), unsupported resource mode, or 'no schema found' for a configured resource.

Source

Thrown at internal/command/jsonplan/plan.go:308

	}

	// output.Checks
	if p.Checks != nil && p.Checks.ConfigResults.Len() > 0 {
		output.Checks = jsonchecks.MarshalCheckStates(p.Checks)
	}

	// output.PriorState
	if sf != nil && !sf.State.Empty() {
		output.PriorState, err = jsonstate.Marshal(sf, schemas)
		if err != nil {
			return nil, fmt.Errorf("error marshaling prior state: %w", err)
		}
	}

	// output.Config
	output.Config, err = jsonconfig.Marshal(config, schemas)
	if err != nil {
		return nil, fmt.Errorf("error marshaling config: %w", err)
	}

	return output, nil
}

// Marshal returns the json encoding of a tofu plan.
func Marshal(
	config *configs.Config,
	p *plans.Plan,
	sf *statefile.File,
	schemas *tofu.Schemas,
) ([]byte, error) {
	output, err := MarshalForLog(config, p, sf, schemas)
	if err != nil {
		return nil, err
	}

	return json.Marshal(output)

View on GitHub (pinned to 3561785c48)

Solutions

  1. Unwrap the error to see which config-marshal failure occurred
  2. If 'no schema found': run 'tofu init' and regenerate the plan
  3. Otherwise align OpenTofu versions between producer and consumer
  4. Report internal-bug cases with the unwrapped message
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := jsonplan.Marshal(config, plan, sf, schemas); err != nil {
    if strings.Contains(err.Error(), "marshaling config") {
        // delegate to the jsonconfig failure family: schema miss -> tofu init; mode/type errors -> version realignment
    }
    return err
}

Prevention

When it happens

Trigger: Any jsonconfig failure over the plan's config: missing provider schema for a configured resource type, unknown resource mode from version skew, or a type constraint that fails cty JSON serialization.

Common situations: 'tofu show -json' on plans/configs from other environments or versions; providers not initialized in the reading environment.

Related errors


AI-assisted analysis of opentofu/opentofu@3561785c48 (2026-08-15). Data as JSON: /api/errors/10b15613f6561f81. Report an issue: GitHub.