gastownhall/beads · error

failed to parse work item response: %w

Error message

failed to parse work item response: %w

What it means

CreateTaskWorkItem got valid JSON back from the GraphQL workItemCreate mutation, but the payload could not be unmarshaled into the expected nested response struct (workItemCreate.workItem.workItemType etc.). The mutation may have returned an error-shaped body or a schema different from what the client expects.

Source

Thrown at internal/gitlab/client.go:624

		return nil, err
	}

	var resp struct {
		WorkItemCreate struct {
			Errors   []string `json:"errors"`
			WorkItem *struct {
				ID     string `json:"id"`
				IID    string `json:"iid"`
				Title  string `json:"title"`
				WebURL string `json:"webUrl"`
				Type   struct {
					Name string `json:"name"`
				} `json:"workItemType"`
			} `json:"workItem"`
		} `json:"workItemCreate"`
	}
	if err := json.Unmarshal(data, &resp); err != nil {
		return nil, fmt.Errorf("failed to parse work item response: %w", err)
	}
	if len(resp.WorkItemCreate.Errors) > 0 {
		return nil, fmt.Errorf("work item creation failed: %s", resp.WorkItemCreate.Errors[0])
	}
	if resp.WorkItemCreate.WorkItem == nil {
		return nil, fmt.Errorf("work item creation returned nil")
	}

	wi := resp.WorkItemCreate.WorkItem
	return &WorkItem{
		ID:    wi.ID,
		IID:   wi.IID,
		Title: wi.Title,
		Type:  wi.Type.Name,
	}, nil
}

// GetWorkItemGID looks up the global ID of a work item by its project-scoped IID.

View on GitHub (pinned to 71377f2769)

Solutions

  1. Log the raw GraphQL data payload to compare against the expected struct shape.
  2. Verify the GitLab version's workItemCreate mutation schema matches the client's struct.
  3. Check whether the response contains data:null plus errors — handle before unmarshaling into the nested struct.
  4. Update the client's response struct to match the instance's GraphQL schema (introspect with a GraphQL IDE).

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

// introspect the instance schema before relying on workItemCreate
const q = `{ __type(name: "WorkItemCreatePayload") { fields { name } } }`

Try / catch

item, err := client.CreateTaskWorkItem(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "failed to parse work item response") {
        // schema drift: log raw payload, refresh client struct or pin GitLab version
    }
    return err
}

Prevention

When it happens

Trigger: Calling CreateTaskWorkItem where the mutation response omits or restructures fields the struct expects — e.g. workItemType removed/renamed in a GitLab upgrade, or the response being a GraphQL errors envelope whose shape mismatches resp.Data after graphqlRequest returns only result.Data.

Common situations: GitLab minor-version schema drift on workItemCreate; the mutation returning data:null with errors (unmarshaled into zeroed struct, but here a type mismatch such as a string where an object is expected); querying an instance where work items are disabled.

Understand the failure class

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/ac2cf39df0d01a16. Report an issue: GitHub.