gastownhall/beads · error

parse create database response: %w

Error message

parse create database response: %w

What it means

CreateDatabase POSTs to /databases and unmarshals the response into Database. If the returned body can't be parsed into that struct, the json error is wrapped with this message.

Source

Thrown at internal/notion/client.go:115

	request := map[string]interface{}{
		"parent": map[string]interface{}{
			"type":    "page_id",
			"page_id": parentPageID,
		},
		"title":     richTextRequest(title),
		"is_inline": false,
		"initial_data_source": map[string]interface{}{
			"title":      richTextRequest(title),
			"properties": BuildInitialDataSourceProperties(),
		},
	}
	body, err := c.doRequest(ctx, http.MethodPost, "/databases", request)
	if err != nil {
		return nil, err
	}
	var db Database
	if err := json.Unmarshal(body, &db); err != nil {
		return nil, fmt.Errorf("parse create database response: %w", err)
	}
	return &db, nil
}

func (c *Client) QueryDataSource(ctx context.Context, dataSourceID string) ([]Page, error) {
	var pages []Page
	var cursor string
	for pageNum := 0; pageNum < maxQueryPages; pageNum++ {
		request := map[string]interface{}{
			"page_size":   maxPageSize,
			"result_type": "page",
		}
		if cursor != "" {
			request["start_cursor"] = cursor
		}

		body, err := c.doRequest(ctx, http.MethodPost, "/data_sources/"+url.PathEscape(dataSourceID)+"/query", request)
		if err != nil {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Log the raw response body to see what Notion returned.
  2. Pin/update the Notion API version header and update the Database struct accordingly.
  3. Retry after confirming no proxy rewrites responses.
Defensive patterns

Strategy: type-guard

Type guard

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

Try / catch

db, err := client.CreateDatabase(ctx, parentPageID, title)
if err != nil {
    var jsonErr *json.UnmarshalTypeError
    if errors.As(err, &jsonErr) {
        return fmt.Errorf("unexpected create-database response: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: POST /databases returns 200/201 with a body failing json.Unmarshal into Database: schema drift, non-JSON error payload, or partial response.

Common situations: Notion API version mismatch; proxy interference; response shape changed for databases created via data-source parents.

Related errors


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