dagger/dagger · error
parse module registry: %w
Error message
parse module registry: %w
What it means
This error wraps any failure to parse the embedded JSON module registry into a list of registryModule entries. It is thrown by parseModuleRegistry when json.Unmarshal of the compiled-in registry data fails. Because the registry data is embedded at build time, this almost always indicates a corrupted or malformed registry blob rather than a user-actionable problem.
Source
Thrown at internal/cmd/dagger/mod.go:102
// The module is recommended when any pattern matches at least one file.
// An empty list means never recommended.
Recommend []string `json:"recommend,omitempty"`
}
// embeddedModuleRegistry is the registry baked in at build time.
//
//go:embed modules.json
var embeddedModuleRegistry []byte
// loadModuleRegistry returns the embedded module registry.
func loadModuleRegistry() ([]registryModule, error) {
return parseModuleRegistry(embeddedModuleRegistry)
}
func parseModuleRegistry(data []byte) ([]registryModule, error) {
var mods []registryModule
if err := json.Unmarshal(data, &mods); err != nil {
return nil, fmt.Errorf("parse module registry: %w", err)
}
return mods, nil
}
// searchModuleRegistry returns modules whose name or description match query
// (case-insensitive substring), sorted by name. An empty query returns all.
func searchModuleRegistry(mods []registryModule, query string) []registryModule {
out := make([]registryModule, 0, len(mods))
q := strings.ToLower(query)
for _, m := range mods {
if q == "" ||
strings.Contains(strings.ToLower(m.Name), q) ||
strings.Contains(strings.ToLower(m.Description), q) {
out = append(out, m)
}
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
return outView on GitHub (pinned to 82ba2681db)
Solutions
- Regenerate or restore the embedded registry JSON so it is valid JSON matching []registryModule
- Run 'dagger mod registry' style tests (TestParseModuleRegistry) to confirm the embedded data parses
- Rebuild the binary so the embedded registry matches the current registryModule struct
Example fix
// before
var mods []registryModule
if err := json.Unmarshal(data, &mods); err != nil {
return nil, fmt.Errorf("parse module registry: %w", err)
}
// after
// fix the source data instead of code:
// regenerate embeddedModuleRegistry so that `json.Unmarshal(data, &[]registryModule{})` succeeds Defensive patterns
Strategy: try-catch
Validate before calling
var probe []registryModule
if err := json.Unmarshal(embeddedModuleRegistry, &probe); err != nil {
// surface build-time registry corruption early
log.Fatalf("embedded module registry invalid: %v", err)
} Type guard
func isValidRegistry(data []byte) bool {
var mods []registryModule
return json.Unmarshal(data, &mods) == nil
} Try / catch
mods, err := parseModuleRegistry(embeddedModuleRegistry)
if err != nil {
var ue *json.UnmarshalTypeError
if errors.As(err, &ue) { /* schema mismatch handling */ }
return fmt.Errorf("registry unavailable: %w", err)
} Prevention
- Validate the embedded registry in CI (TestParseModuleRegistry) at build time
- Regenerate the registry via the standard script instead of hand-editing JSON
- Add a schema check whenever registryModule struct fields change
When it happens
Trigger: Calling parseModuleRegistry (directly or via loadModuleRegistry) when the embedded module registry JSON is malformed, has an unexpected schema (e.g. fields not matching registryModule), or fails to unmarshal into []registryModule.
Common situations: Corrupted build artifact or stale embedded registry after a schema change; a registry regeneration script emitted invalid JSON; running tests (TestParseModuleRegistry/TestEmbeddedModuleRegistryParses) against a hand-edited registry file.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- unmarshal index: %w
- parsing legacy config: %w
- failed to decode module config: %w
- decode %q: %w
- decode tag list from %q: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/5d0163a41baf179b.
Report an issue: GitHub.