t8y2/dbx · error

failed to read enum values: %w

Error message

failed to read enum values: %w

What it means

After getTypeDetails classifies a type as an enum, it runs customTypeEnumMembers, which executes the prebuilt enum-members catalog SQL (ordered by enumsortorder) via metadataQuery. If that query fails to execute, the error is wrapped with 'failed to read enum values' and returned, so the enum's member list cannot be produced.

Source

Thrown at agents/drivers/kingbase-go/kingbase_metadata.go:796

	properties.AnalyzeFunction = nullStringPtr(analyzeFn)
	if typlen.Valid && typlen.Int64 > 0 {
		value := int32(typlen.Int64)
		properties.Internallength = &value
	}
	properties.PassedByValue = &typbyval
	if typalign != "" {
		properties.Alignment = &typalign
	}
	if typstorage != "" {
		properties.Storage = &typstorage
	}
	return properties
}

func (s *server) customTypeEnumMembers(sqlTemplate string, oid int64) ([]customTypeMember, error) {
	rows, err := s.metadataQuery(fmt.Sprintf(sqlTemplate, oid))
	if err != nil {
		return nil, fmt.Errorf("failed to read enum values: %w", err)
	}
	defer rows.Close()
	var members []customTypeMember
	index := 0
	for rows.Next() {
		var label string
		var sortOrder float64
		if err := rows.Scan(&label, &sortOrder); err != nil {
			return nil, err
		}
		// enumsortorder is float4; ALTER TYPE ... ADD VALUE BEFORE/AFTER can
		// yield fractional values. Use the ORDER BY position for a unique key.
		index++
		members = append(members, customTypeMember{Ordinal: int32(index), EnumValue: &label})
	}
	return members, rows.Err()
}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Read the wrapped inner error (%w) to see the underlying SQL/scan failure cause
  2. Grant the connecting role SELECT on the enum catalog (pg_enum / sys_enum) and joined catalogs
  3. Verify the server mode flag (postgresCatalog vs sys_catalog) matches the actual Kingbase instance layout
  4. Retry the metadata call if the inner error indicates a transient connection issue

Example fix

// before
rows, err := s.metadataQuery(fmt.Sprintf(sqlTemplate, oid))
// after — ensure the query template matches the active catalog
if rows == nil || err != nil { return nil, fmt.Errorf("failed to read enum values (oid=%d): %w", oid, err) }
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure privileges and mode before the call
if !roleCanSelect("pg_enum", "pg_type") && !roleCanSelect("sys_enum", "sys_type") { grantEnumCatalogAccess() }
if driverModeMismatch() { reconfigureDriverMode() }

Type guard

func isEnumDetails(details *customTypeDetails) bool {
  return details != nil && details.Kind == "enum"
} // only then expect a non-error member list

Try / catch

details, err := server.GetTypeDetails(schema, name)
if err != nil && strings.Contains(err.Error(), "failed to read enum values") {
  if isTransient(err) { return retryWithBackoff() }
  return fmt.Errorf("enum members unreadable for %s.%s: %w", schema, name, err)
}

Prevention

When it happens

Trigger: Calling the type details API on an enum type (typtype 'e') whose enum-label catalog query (e.g. pg_enum/sys_enum join) fails — wrong template interpolation of the OID, missing catalog table, insufficient privileges, or connection dropped mid-query.

Common situations: Restricted role lacking SELECT on enum catalogs; Kingbase instance where the enum catalog table name differs from the expected pg/sys schema layout; transient connection failure between the general type lookup and the members query.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/9eb9a24bd335246d. Report an issue: GitHub.