gastownhall/beads · error

parse data source response: %w

Error message

parse data source response: %w

What it means

RetrieveDataSource fetches a Notion data source by ID and unmarshals into DataSource. A body that can't be parsed into that struct produces this wrapped error.

Source

Thrown at internal/notion/client.go:71

	body, err := c.doRequest(ctx, http.MethodGet, "/users/me", nil)
	if err != nil {
		return nil, err
	}
	var user User
	if err := json.Unmarshal(body, &user); err != nil {
		return nil, fmt.Errorf("parse current user response: %w", err)
	}
	return &user, nil
}

func (c *Client) RetrieveDataSource(ctx context.Context, dataSourceID string) (*DataSource, error) {
	body, err := c.doRequest(ctx, http.MethodGet, "/data_sources/"+url.PathEscape(dataSourceID), nil)
	if err != nil {
		return nil, err
	}
	var ds DataSource
	if err := json.Unmarshal(body, &ds); err != nil {
		return nil, fmt.Errorf("parse data source response: %w", err)
	}
	return &ds, nil
}

func (c *Client) RetrieveDatabase(ctx context.Context, databaseID string) (*Database, error) {
	body, err := c.doRequest(ctx, http.MethodGet, "/databases/"+url.PathEscape(databaseID), nil)
	if err != nil {
		return nil, err
	}
	var db Database
	if err := json.Unmarshal(body, &db); err != nil {
		return nil, fmt.Errorf("parse database response: %w", err)
	}
	return &db, nil
}

func (c *Client) CreateDatabase(ctx context.Context, parentPageID, title string) (*Database, error) {
	parentPageID = strings.TrimSpace(parentPageID)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Log the raw body to inspect the unexpected payload.
  2. Confirm the dataSourceID is a valid Notion data source ID.
  3. Update the client/DataSource struct to match your Notion API version.
Defensive patterns

Strategy: type-guard

Type guard

func isNotionParseError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "parse data source response")
}

Try / catch

ds, err := client.RetrieveDataSource(ctx, id)
if err != nil {
    if strings.Contains(err.Error(), "parse data source response") {
        return fmt.Errorf("check ID and API version: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: GET /data_sources/{id} returns 200 with a body that fails json.Unmarshal into DataSource: unexpected schema or non-JSON payload.

Common situations: Data source ID typo'd such that another endpoint responds; API version drift changing the data_source schema; intercepted response from a proxy.

Related errors


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