dagger/dagger · error

load current workspace

Error message

load current workspace: %w

What it means

This error wraps any failure from srv.Select when resolving the `currentWorkspace` root field on the session's dagql server, inside workspaceArgValue. workspaceArgValue is called when assembling a required (non-null) Workspace-typed argument that the caller left unset: it tries the context-bound Workspace first, and if none is bound (and the call is not inside a running module function), it falls back to loading the ambient current workspace. If that GraphQL selection fails for any reason (no current workspace, resolver error, server/instance issues), the underlying error is wrapped with this message and propagated to the caller building the selector (boundWorkspaceArgs / boundWorkspaceInput).

Solutions

  1. Run the call inside a context where a Workspace is bound — use WorkspaceToContext(ctx, ws) so workspaceArgValue takes the bound-Workspace path and never selects currentWorkspace.
  2. Explicitly pass the Workspace argument in `named` inputs to WithBoundWorkspaceArgs so the unset-arg fallback never runs.
  3. Check the wrapped (%w) underlying error: if it says the field doesn't exist or no workspace is current, verify the engine/session actually has a current workspace (dagger CLI session started in a module/workspace directory).
  4. If the call legitimately has no workspace, ensure it's inside a module function (callerInModuleFunction true) so nil is returned and dagql reports the missing argument by name instead of this wrapped failure.

Example fix

// before: assembling args with no workspace bound
named := core.WithBoundWorkspaceArgs(ctx, srv, specs, named)
// after: bind the workspace first so currentWorkspace is never queried
ws, err := srv.Select(ctx, srv.Root(), ...currentWorkspace...) // or obtain otherwise
ctx = core.WorkspaceToContext(ctx, ws)
named := core.WithBoundWorkspaceArgs(ctx, srv, specs, named)
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure a workspace is bound before building args
if _, ok := core.WorkspaceFromContext(ctx); !ok {
    // load/bind current workspace first
    var ws dagql.ObjectResult[*core.Workspace]
    if err := srv.Select(ctx, srv.Root(), &ws, dagql.Selector{Field: "currentWorkspace"}); err != nil {
        return fmt.Errorf("no workspace available: %w", err)
    }
    ctx = core.WorkspaceToContext(ctx, ws)
}

Type guard

func hasBoundWorkspace(ctx context.Context) bool {
    ws, ok := core.WorkspaceFromContext(ctx)
    return ok && ws.Self() != nil
}

Try / catch

named := core.WithBoundWorkspaceArgs(ctx, srv, specs, named) // errors are returned, not panicked
if err != nil { // propagate from your own wrapper that calls boundWorkspaceInput
    return fmt.Errorf("could not resolve workspace for required argument: %w", err)
}

Prevention

When it happens

Trigger: Calling WithBoundWorkspaceArgs (or otherwise triggering boundWorkspaceInput/boundWorkspaceArgs) for a spec with a required Workspace argument, when: (a) no Workspace is bound via WorkspaceToContext, (b) the call is not inside a module function (callerInModuleFunction false), and (c) srv.Select(ctx, srv.Root(), &ws, {Field: "currentWorkspace"}) fails — e.g. the session has no currentWorkspace, the resolver errors, or the server/root is in a bad state.

Common situations: Running a module function or framework entrypoint (check, group, up proxies) outside of a workspace-aware session so `currentWorkspace` cannot resolve; stale/errored engine session where the root query can't serve currentWorkspace; calling library APIs that auto-fill Workspace args from a plain SDK client session with no workspace loaded; version mismatches where the served schema no longer exposes currentWorkspace.

Related errors


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

Appendix: source

Thrown at core/workspace_context.go:79

			return nil, fmt.Errorf("get bound workspace ID: %w", err)
		}
		return dagql.NewID[*Workspace](wsID), nil
	}
	if srv == nil {
		return nil, nil
	}
	// A running module function must pass a Workspace to its dependencies
	// explicitly, so it doesn't silently inherit its caller's.
	if inModuleFunction, err := callerInModuleFunction(ctx); err != nil {
		return nil, err
	} else if inModuleFunction {
		return nil, nil
	}
	var ws dagql.ObjectResult[*Workspace]
	if err := srv.Select(ctx, srv.Root(), &ws, dagql.Selector{
		Field: "currentWorkspace",
	}); err != nil {
		return nil, fmt.Errorf("load current workspace: %w", err)
	}
	wsID, err := ws.ID()
	if err != nil {
		return nil, fmt.Errorf("get current workspace ID: %w", err)
	}
	return dagql.NewID[*Workspace](wsID), nil
}

// WithBoundWorkspaceArgs supplies the workspace for any required Workspace
// argument in specs that named doesn't already carry.
//
// Callers that assemble a selector themselves — the entrypoint proxies building
// their inner constructor call, like ModTreeNode.DagqlValue — have to fill a
// required Workspace before selecting, since dagql's injection hook runs after
// the non-null check.
func WithBoundWorkspaceArgs(
	ctx context.Context,
	srv *dagql.Server,

View on GitHub (pinned to 82ba2681db)