Skip to content

Enhanced Message Validation with Schema Introspection for Publishers, Services, and Actions #1340

@mahmoud-ghalayini

Description

@mahmoud-ghalayini

The Problem

Current message validation in rclnodejs is minimal:

  1. Cryptic errors - Publishing invalid messages results in generic "serialization failed" errors with no indication of what field or type is wrong
  2. Silent failures - Unknown fields are silently ignored, leading to hard-to-debug issues
  3. No schema introspection - No programmatic way to inspect message structure at runtime

Solution

Enhance message validation with:

1. Schema Introspection APIs

  • getMessageSchema(typeClass) - Get full schema for any message type
  • getFieldNames(typeClass) - List field names
  • getFieldType(typeClass, fieldName) - Get type info for specific field

2. Validation Functions

  • validateMessage(obj, typeClass, options) - Returns {valid, issues[]}
  • assertValidMessage(obj, typeClass, options) - Throws on invalid
  • createMessageValidator(typeClass, options) - Reusable validator

3. Structured Error Reporting

  • New MessageValidationError class with field-level issue details
  • ValidationProblem enum: TYPE_MISMATCH, UNKNOWN_FIELD, MISSING_FIELD, etc.

4. Validation Options

  • strict: true - Error on unknown fields
  • checkTypes: true - Validate field types
  • Nested message validation support

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions