risingwavelabs/risingwave · error · SinkError

Encode error: {0}

Error message

Encode error: {0}

What it means

Variant of `SinkError` produced when the sink's encoder fails, typically because incoming row data cannot be encoded into the target format (JSON/Avro/Protobuf/Debezium) according to the sink schema — e.g. a payload that doesn't validate against the registered schema.

Source

Thrown at src/connector/src/sink/mod.rs:1104

pub type Result<T> = std::result::Result<T, SinkError>;

#[derive(Error, Debug)]
pub enum SinkError {
    #[error("Kafka error: {0}")]
    Kafka(#[from] rdkafka::error::KafkaError),
    #[error("Kinesis error: {0}")]
    Kinesis(
        #[source]
        #[backtrace]
        anyhow::Error,
    ),
    #[error("Remote sink error: {0}")]
    Remote(
        #[source]
        #[backtrace]
        anyhow::Error,
    ),
    #[error("Encode error: {0}")]
    Encode(String),
    #[error("Avro error: {0}")]
    Avro(#[from] apache_avro::Error),
    #[error("Iceberg error: {0}")]
    Iceberg(
        #[source]
        #[backtrace]
        anyhow::Error,
    ),
    #[error("config error: {0}")]
    Config(
        #[source]
        #[backtrace]
        anyhow::Error,
    ),
    #[error("coordinator error: {0}")]
    Coordinator(
        #[source]

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Read the inner message to see which field/value failed encoding and fix the upstream data or the column type
  2. Recreate or alter the sink so its schema matches the current source (e.g. re-register the Avro schema with schema registry)
  3. Cast or sanitize problematic columns upstream (`SELECT CAST(...)` in the sink's query) so they fit the target format

Example fix

-- before
CREATE SINK s FROM mv INTO kafka WITH (connector='kafka', format='avro', ...);
-- fails on incompatible decimal column

-- after
CREATE SINK s FROM (SELECT id, CAST(amount AS DOUBLE) AS amount FROM mv) INTO kafka
  WITH (connector='kafka', format='avro', ...);
Defensive patterns

Strategy: validation

Validate before calling

// ensure every column in the sink query matches the target schema before CREATE SINK
-- compare: SELECT column_name, data_type FROM rw_columns WHERE relation = 'mv';
-- against the registered Avro/JSON/Protobuf schema

Try / catch

match err {
    SinkError::Encode(msg) => {
        log::error!("sink encode failed: {msg}"); // inspect field/value reported, fix data or schema
    }
    e => return Err(e.into()),
}

Prevention

When it happens

Trigger: Encoding a stream chunk during sink write when the row violates the target format: a field type mismatch vs the Avro schema, missing NOT NULL-compatible field, invalid protobuf payload, or a malformed value the encoder cannot serialize.

Common situations: Upstream schema evolved but the sink's registered Avro/JSON schema (schema registry) is stale; decimal/nullable handling differences; sink created before an ALTER added columns the encoder can't map.

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 risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/6566d8d1d97dcce3. Report an issue: GitHub.