JuliusBrussee/caveman · error

ccr: unknown object type

Error message

ccr: unknown object type %q

What it means

prepareObject validates every Object before it is written to the CCR SQLite store. The object's Type field must exactly match one of the registered object types (the objectTypes map, e.g. ObjectDocumentationExcerpt, ObjectBrowserSnapshot, ObjectRepositoryMap, ObjectEvidenceBundle); any other value is rejected with this error and nothing is stored. It is a closed-enum type check that keeps the recovery store's records well-formed.

Solutions

  1. Set obj.Type to one of the library's exported object type constants (e.g. ObjectDocumentationExcerpt, ObjectBrowserSnapshot, ObjectRepositoryMap, ObjectEvidenceBundle) instead of a string literal
  2. Check for typos or casing differences between your value and the constant names
  3. If migrating from an older version, update code that referenced removed/renamed Object type constants to the current set
  4. Inspect the objectTypes map in engine/ccr/store.go for the exact accepted set of types

Example fix

// before
obj := ccr.Object{Type: "documentation", SessionID: sid, Payload: p}
// after
obj := ccr.Object{Type: ccr.ObjectDocumentationExcerpt, SessionID: sid, Payload: p}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the object type before calling PutObject
func validObjectType(t ccr.ObjectType) bool {
  switch t {
  case ccr.ObjectDocumentationExcerpt, ccr.ObjectBrowserSnapshot,
    ccr.ObjectRepositoryMap, ccr.ObjectEvidenceBundle:
    return true
  }
  return false
}
if !validObjectType(obj.Type) { return fmt.Errorf("unsupported object type %q", obj.Type) }

Type guard

func isStoredObject(v any) (ccr.Object, bool) {
  obj, ok := v.(ccr.Object)
  if !ok || !validObjectType(obj.Type) || strings.TrimSpace(obj.SessionID) == "" {
    return ccr.Object{}, false
  }
  return obj, true
}

Try / catch

if _, err := store.PutObject(ctx, obj); err != nil {
  if strings.Contains(err.Error(), "unknown object type") {
    return fmt.Errorf("object type %q is not part of the CCR enum; use an exported Object* constant: %w", obj.Type, err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling PutObject (or internal putObject) with an Object whose Type string is empty, mistyped, or not one of the enumerated Object* constants — e.g. a raw string like "doc" instead of the exported constant, or a constant removed/renamed in a version change.

Common situations: Constructing an Object by hand with a free-form type string instead of the library's exported Object* constants; upgrading the library where an object type constant was renamed or deleted; copying sample code that used an older/invalid type value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/3f4309e043c910b9. Report an issue: GitHub.

Appendix: source

Thrown at engine/ccr/store.go:107

	Currentness        Currentness `json:"currentness"`
	Lifecycle          Lifecycle   `json:"lifecycle"`
	Dependencies       []string    `json:"dependencies"`
	OriginalByteLength int         `json:"original_byte_length"`
	StoredByteLength   int         `json:"stored_byte_length"`
	Data               []byte      `json:"data"`
}

var objectTypes = map[ObjectType]struct{}{
	ObjectFileObservation: {}, ObjectSearchResult: {}, ObjectCommandResult: {},
	ObjectTestResult: {}, ObjectBuildResult: {}, ObjectDiffSnapshot: {},
	ObjectTaskContract: {}, ObjectTaskDecision: {}, ObjectExecutionState: {},
	ObjectDocumentationExcerpt: {}, ObjectBrowserSnapshot: {},
	ObjectRepositoryMap: {}, ObjectEvidenceBundle: {},
}

func prepareObject(obj Object) (Object, error) {
	if _, ok := objectTypes[obj.Type]; !ok {
		return Object{}, fmt.Errorf("ccr: unknown object type %q", obj.Type)
	}
	if strings.TrimSpace(obj.SessionID) == "" {
		return Object{}, errors.New("ccr: typed object session_id is required")
	}
	if obj.Currentness == "" {
		obj.Currentness = Current
	}
	if obj.Currentness != Current && obj.Currentness != Stale && obj.Currentness != Archived {
		return Object{}, fmt.Errorf("ccr: unknown currentness %q", obj.Currentness)
	}
	if obj.Lifecycle == "" {
		obj.Lifecycle = Hot
	}
	if obj.Lifecycle != Hot && obj.Lifecycle != Warm && obj.Lifecycle != Cold && obj.Lifecycle != LifecycleArchived {
		return Object{}, fmt.Errorf("ccr: unknown lifecycle %q", obj.Lifecycle)
	}
	if obj.CreatedAt.IsZero() {
		obj.CreatedAt = time.Now().UTC()

View on GitHub (pinned to 3ee70a1026)