gastownhall/beads · error

failed to parse work item types response: %w

Error message

failed to parse work item types response: %w

What it means

This error means GetWorkItemTypes received a response but json.Unmarshal of the raw body into the generic listResponse envelope failed. The body was not the expected {"value": [...]} JSON — commonly an HTML page, empty body, or malformed JSON.

Source

Thrown at internal/ado/client.go:597

	var projects []Project
	if err := json.Unmarshal(envelope.Value, &projects); err != nil {
		return nil, fmt.Errorf("failed to parse projects value: %w", err)
	}
	return projects, nil
}

// GetWorkItemTypes returns the work item types available in the project.
func (c *Client) GetWorkItemTypes(ctx context.Context) ([]WorkItemType, error) {
	urlStr := addAPIVersion(c.apiBase() + "/wit/workitemtypes")
	respBody, err := c.doRequest(ctx, http.MethodGet, urlStr, "", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get work item types: %w", err)
	}

	var envelope listResponse
	if err := json.Unmarshal(respBody, &envelope); err != nil {
		return nil, fmt.Errorf("failed to parse work item types response: %w", err)
	}

	var types []WorkItemType
	if err := json.Unmarshal(envelope.Value, &types); err != nil {
		return nil, fmt.Errorf("failed to parse work item types value: %w", err)
	}
	return types, nil
}

// GetWorkItemStates returns the states for a given work item type.
func (c *Client) GetWorkItemStates(ctx context.Context, typeName string) ([]WorkItemState, error) {
	urlStr := addAPIVersion(c.apiBase() + "/wit/workitemtypes/" + url.PathEscape(typeName) + "/states")
	respBody, err := c.doRequest(ctx, http.MethodGet, urlStr, "", nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get work item states: %w", err)
	}

	var envelope listResponse

View on GitHub (pinned to 71377f2769)

Solutions

  1. Capture and inspect the raw response body to identify what was returned instead of JSON
  2. Verify the request is going to the API endpoint, not behind an HTML auth wall or proxy
  3. Retry transient failures; truncated bodies commonly follow network blips
  4. Confirm the client's project/org URL configuration is an API base
Defensive patterns

Strategy: try-catch

Try / catch

types, err := client.GetWorkItemTypes(ctx)
if err != nil {
  if strings.Contains(err.Error(), "failed to parse work item types response") {
    return nil, fmt.Errorf("non-JSON response from workitemtypes endpoint (proxy/auth page?): %w", err)
  }
  return nil, err
}

Prevention

When it happens

Trigger: Calling GetWorkItemTypes when the endpoint returns non-JSON: HTML login/proxy page with 200, empty response, truncated body, or an ADO error page.

Common situations: Auth proxy intercepting requests; hitting the web UI URL instead of the API; transient network truncation; ADO service degradation returning HTML.

Understand the failure class

Related errors


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