dagger/dagger · error

failed to create instance for module %q: %w

Error message

failed to create instance for module %q: %w

What it means

The final step of asModule wraps the built core.Module in a dagql instance via dagql.NewObjectResultForCurrentCall, which registers the result with the current GraphQL call. If instance creation fails, the error is wrapped as 'failed to create instance for module %q' with the module name.

Source

Thrown at core/schema/modulesource.go:4232

	if args.LegacyWorkspaceConfigJSON != "" {
		if err := mod.ApplyWorkspaceDefaultsToTypeDefs(ctx, dag); err != nil {
			return inst, err
		}
	}
	if args.LegacyArgCustomizationsJSON != "" {
		var customizations []*modules.ModuleConfigArgument
		if err := json.Unmarshal([]byte(args.LegacyArgCustomizationsJSON), &customizations); err != nil {
			return inst, fmt.Errorf("decoding legacy arg customizations: %w", err)
		}
		mod.LegacyArgCustomizations = customizations
		if err := mod.ApplyLegacyCustomizationsToTypeDefs(ctx, dag, customizations); err != nil {
			return inst, err
		}
	}

	inst, err = dagql.NewObjectResultForCurrentCall(ctx, dag, mod)
	if err != nil {
		return inst, fmt.Errorf("failed to create instance for module %q: %w", src.Self().ModuleName, err)
	}
	return inst, nil
}

// load the given module source's dependencies as modules
// BuildLegacyAsModuleArgs is the single builder for the asModule args salted
// into AsModuleVariantDigest, so every load path yields one module identity.
func BuildLegacyAsModuleArgs(
	nameOverride string,
	legacyDefaultPath bool,
	defaultPathContextSourceRef string,
	defaultPathContextSourcePin string,
	configDefaults map[string]any,
	defaultsFromDotEnv bool,
	argCustomizations []*modules.ModuleConfigArgument,
) ([]dagql.NamedInput, error) {
	args := []dagql.NamedInput{}
	if nameOverride != "" {

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Inspect the wrapped inner error; this is almost always an engine-internal issue
  2. Ensure asModule is invoked through the GraphQL API within a dagql call, not called directly from Go outside a server context
  3. Retry the module load; transient engine failures can hit the instance registry
  4. Report a bug with the inner error and engine version if it reproduces consistently

Example fix

// before (Go, direct call outside dagql)
inst, err := schema.moduleSourceAsModule(ctx, src, args)
// after: query via the client
mod := dag.ModuleSource(dirPath).AsModule()
Defensive patterns

Strategy: try-catch

Try / catch

try { mod = src.asModule() } catch (e) { if (String(e).includes('failed to create instance for module')) { log.error('dagql instance failure:', e.cause ?? e) } throw e }

Prevention

When it happens

Trigger: Calling asModule where the module itself built successfully but dagql.NewObjectResultForCurrentCall fails — typically because there is no current dagql call context or an internal dagql allocation/registration error.

Common situations: Invoking the asModule resolver outside a proper GraphQL call context (tests, custom tooling calling core functions directly); internal engine bugs; resource exhaustion during instance registration.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/99a9df019653034f. Report an issue: GitHub.