dagger/dagger · error
encode workspace config: %w
Error message
encode workspace config: %w
What it means
When the module carries a WorkspaceConfig, buildScaleOutModuleQuery marshals it to JSON to pass as legacyWorkspaceConfigJson to the asModule selection. This error wraps a json.Marshal failure on the workspace config, meaning the config structure contains values that cannot be serialized to JSON.
Source
Thrown at core/modtree.go:567
if mod.LegacyDefaultPath {
query = query.Arg("legacyDefaultPath", true)
}
if mod.ContextSource.Valid {
contextSrc := mod.ContextSource.Value.Self()
if contextSrc != nil {
contextRef := contextSrc.AsString()
if contextRef != "" && (contextRef != modSrc.AsString() || contextSrc.Pin() != modSrc.Pin()) {
query = query.Arg("defaultPathContextSourceRef", contextRef)
if contextPin := contextSrc.Pin(); contextPin != "" {
query = query.Arg("defaultPathContextSourcePin", contextPin)
}
}
}
}
if len(mod.WorkspaceConfig) > 0 {
workspaceConfigJSON, err := json.Marshal(mod.WorkspaceConfig)
if err != nil {
return nil, fmt.Errorf("encode workspace config: %w", err)
}
query = query.Arg("legacyWorkspaceConfigJson", string(workspaceConfigJSON))
if mod.DefaultsFromDotEnv {
query = query.Arg("legacyDefaultsFromDotEnv", true)
}
}
if len(mod.LegacyArgCustomizations) > 0 {
customizationsJSON, err := json.Marshal(mod.LegacyArgCustomizations)
if err != nil {
return nil, fmt.Errorf("encode arg customizations: %w", err)
}
query = query.Arg("legacyArgCustomizationsJson", string(customizationsJSON))
}
return query, nil
}
// Initialize a standalone dagql server for querying the given module
func dagqlServerForModule(ctx context.Context, mod dagql.ObjectResult[*Module]) (*dagql.Server, error) {View on GitHub (pinned to 82ba2681db)
Solutions
- Inspect the wrapped marshal error to find the offending field in the workspace config.
- Ensure the Module object was built from decoded JSON config (dagger.json) rather than hand-populated structures.
- Validate dagger.json workspace section parses cleanly before running scale-out commands.
- Report/upgrade if triggered by valid config — indicates a marshaling regression.
Defensive patterns
Strategy: validation
Validate before calling
// sanity-check the workspace config parses as JSON before module load
const cfg = JSON.parse(fs.readFileSync('dagger.json', 'utf8'));
if (cfg.workspace) JSON.stringify(cfg.workspace); // throws early on bad shapes Prevention
- Only populate WorkspaceConfig from decoded JSON, never hand-built structures.
- Validate dagger.json with a schema/linter in CI.
- Update tooling together so config types stay marshalable.
When it happens
Trigger: Scale-out module load where mod.WorkspaceConfig is non-empty and json.Marshal(mod.WorkspaceConfig) fails — e.g. unsupported types (channels, funcs, cycles) somehow present in the config map, or NaN/invalid values.
Common situations: Rare in practice since WorkspaceConfig comes from decoded JSON; can occur with programmatically constructed Module objects containing non-JSON-serializable fields, or custom marshaler errors on the config type.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- encode arg customizations: %w
- marshal: %w
- marshal persisted generated code payload: %w
- decode persisted generated code payload: %w
- decode persisted container withEntrypoint lazy payload: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/2c0269b86ce965ad.
Report an issue: GitHub.