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 listResponseView on GitHub (pinned to 71377f2769)
Solutions
- Capture and inspect the raw response body to identify what was returned instead of JSON
- Verify the request is going to the API endpoint, not behind an HTML auth wall or proxy
- Retry transient failures; truncated bodies commonly follow network blips
- 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
- Verify the API host is not behind an HTML auth wall
- Curl the endpoint to confirm JSON body before integrating
- Retry truncated responses; they follow network blips
- Monitor ADO status during service incidents
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse projects response: %w
- failed to parse work item states response: %w
- failed to parse projects value: %w
- failed to parse work item types value: %w
- parsing JSON: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/dfac7b882f7f794a.
Report an issue: GitHub.