pulumi/pulumi · error

creating context: %w

Error message

creating context: %w

What it means

ConfigureStack builds a pulumi.RunInfo from the stack configuration request and calls pulumi.NewContext to create the SDK context for the policy pack. If NewContext fails (e.g. invalid RunInfo), the error is wrapped with 'creating context: %w'. This means the policy pack server could not initialize the Pulumi context that policies receive.

Source

Thrown at sdk/go/pulumi/policyx/server.go:302

	info := pulumi.RunInfo{
		Stack:        req.Stack,
		Project:      req.Project,
		Organization: req.Organization,

		RootDirectory: root,

		MonitorAddr: "",
		EngineAddr:  srv.handshake.EngineAddress,

		Config:           req.Config,
		ConfigSecretKeys: req.ConfigSecretKeys,
		DryRun:           req.DryRun,
		Parallel:         1,
	}
	pctx, err := pulumi.NewContext(context.Background(), info)
	if err != nil {
		return nil, fmt.Errorf("creating context: %w", err)
	}

	srv.stacktags = req.Tags

	srv.policyPack, err = srv.policyPackFactory(pctx)
	if err != nil {
		return nil, fmt.Errorf("failed to create policy pack: %w", err)
	}

	return &pulumirpc.AnalyzerStackConfigureResponse{}, nil
}

func (srv *analyzerServer) Configure(ctx context.Context, req *pulumirpc.ConfigureAnalyzerRequest) (*pbempty.Empty,
	error,
) {
	conf := map[string]PolicyConfig{}
	for k, v := range req.PolicyConfig {
		data, err := v.GetProperties().MarshalJSON()

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Read the wrapped cause (%w) in the error chain to see why NewContext rejected the RunInfo
  2. Ensure Handshake ran first so srv.handshake.EngineAddress is populated
  3. Align the pulumi Go SDK version used by the policy pack with the engine version
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check RunInfo before relying on server behavior
if info.EngineAddr == "" { log.Println("warning: empty engine address") }

Try / catch

if err != nil {
    var ctxErr error
    errors.As(err, &ctxErr) // unwrap 'creating context' cause
    return fmt.Errorf("policy pack context setup failed: %w", err)
}

Prevention

When it happens

Trigger: pulumi.NewContext returns an error when building the context from the AnalyzerStackConfigureRequest fields (Stack, Project, Organization, Config, EngineAddress from the handshake).

Common situations: A nil or malformed handshake leaving EngineAddress empty in RunInfo; engine sending a request with invalid stack/project metadata; SDK version mismatch where NewContext validation rejects the RunInfo.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/1f0db41be42a39e3. Report an issue: GitHub.