larksuite/cli · error

schema spec has neither Type nor Raw

Error message

schema spec has neither Type nor Raw

What it means

renderSpec returns this error when a schema spec defines neither Type nor Raw — there is nothing to render into JSON Schema. resolveSchemaJSON calls renderSpec, and the caller's surrounding per-declaration checks only verify raw bytes are non-empty, so this check closes the gap of a decodes-but-describes-nothing spec. Compile ultimately surfaces it inside the aggregated 'event catalog rejected' message.

Source

Thrown at internal/event/catalog/compile.go:272

		return s.Native, true
	}
	if s.Custom != nil {
		return s.Custom, false
	}
	return nil, false
}

// renderSpec produces a JSON Schema from Type (reflected) or Raw (copied).
func renderSpec(s *SchemaSpec) (json.RawMessage, error) {
	if s.Type != nil {
		return schemas.FromType(s.Type), nil
	}
	if len(s.Raw) > 0 {
		buf := make(json.RawMessage, len(s.Raw))
		copy(buf, s.Raw)
		return buf, nil
	}
	return nil, errors.New("schema spec has neither Type nor Raw")
}

// isPlaceholderSchema rejects declarations whose schema decodes but describes
// nothing: an empty document, empty object, or null. Per-declaration checks
// only see "raw bytes are non-empty" — this closes that gap.
func isPlaceholderSchema(schema json.RawMessage) bool {
	trimmed := bytes.TrimSpace(schema)
	if len(trimmed) == 0 {
		return true
	}
	if bytes.Equal(trimmed, []byte("null")) || bytes.Equal(trimmed, []byte("{}")) {
		return true
	}
	var asMap map[string]json.RawMessage
	if err := json.Unmarshal(trimmed, &asMap); err == nil && len(asMap) == 0 {
		return true
	}
	return false

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Set Schema.Type (e.g. "object") with properties, or
  2. Provide Schema.Raw with a valid pre-built JSON schema document
  3. Re-run catalog compilation to confirm the declaration passes

Example fix

// before
Schema: &catalog.Schema{}
// after
Schema: &catalog.Schema{Type: "object"} // or Schema{Raw: json.RawMessage(`{"type":"object"}`)}
Defensive patterns

Strategy: validation

Validate before calling

if spec.Type == "" && len(spec.Raw) == 0 {
    return fmt.Errorf("schema spec for %q needs Type or Raw", key)
}

Type guard

func hasRenderableSchema(s *catalog.SchemaSpec) bool { return s != nil && (s.Type != "" || len(s.Raw) > 0) }

Try / catch

buf, err := resolveSchemaJSON(spec)
if err != nil {
    // spec has neither Type nor Raw — supply one before compiling
}

Prevention

When it happens

Trigger: Declaring an event catalog schema spec as an empty &Schema{} (zero-value: no Type set, len(Raw)==0), then compiling the catalog.

Common situations: Copied a declaration and forgot to fill the schema; a refactoring dropped the Type field; generated specs produced zero-value schema structs.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/69cb9253bb0bf434. Report an issue: GitHub.