Skip to content

[Question] Query offset command returned error with code 19 #283

@WhereJuly

Description

@WhereJuly

Hello, I try to understand if that exception should be actually treated as the case "query offset is not set" or not.

That comes from the line

const offset = await client.queryOffset({ reference: consumerRef, stream: streamName })

when I try to get the stream offset.

Do I suggest correctly that the code 19 is NO_OFFSET (19) - no stored offset (see)?

Woudl it be better to explicitly re-throw the original error or the wrapped one with the original error code as field, not just a generic Error with Query offset command returned error with code 19 message? This prevents from decide what exactly was the problem.

Or, if the code is 19 just means "offset is not defined" - it is not an error code, and the method should return undefined instead of throwing for code 19.

Kind of:

  public async queryOffset(params: QueryOffsetParams): Promise<bigint> {
    this.logger.debug(`Query Offset...`)
    const res = await this.sendAndWait<QueryOffsetResponse>(new QueryOffsetRequest(params))
    
    // The NO_OFFSET is returned, meaning no offset was stored for this consumer. Not an error in fact.
    // see https://github.com/rabbitmq/rabbitmq-server/blob/v3.9.x/deps/rabbitmq_stream/docs/PROTOCOL.adoc#response-codes
    if(!res.ok && res.code === 19) { return undefined; }

    // For any other codes, we re-throws the original response to make the codes available to the caller
    if (!res.ok) { throw res;  }

    this.logger.debug(`Query Offset response: ${res.ok} with params: '${inspect(params)}'`)

    return res.offsetValue
  }

Would the PR be of a value?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions