nats-io / nats.go

Golang client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
5.48k stars 689 forks source link

Add checks for empty response in JetStream API calls #1642

Open piotrpio opened 4 months ago

piotrpio commented 4 months ago

Proposed change

Add checks for nil in all JetStream API requests in jetstream package.

For example, in upsertConsumer(), a check could be added returning a new error kind:

    if resp.ConsumerInfo == nil {
        return nil, ErrInvalidJetStreamResponse
    }

Package should be scanned for places where API requests are sent, e.g. CRUD operations on streams, consumers, AccountInfo etc.

Use case

While unlikely, it may happen that the server responds to JetStream API requests with unexpected data, neither apiResponse (for errors) nor the actual expected type.

While not common, this can happen e.g. due to server bug and in such cases the client should not panic but simply return an error indicating what happened.

https://github.com/nats-io/nats.go/issues/1641 was a motivation for this proposal.

Contribution

No response

areknoster commented 4 months ago

@piotrpio I'd be happy to implement that, I don't have access to assign myself to the issue

piotrpio commented 4 months ago

Sorry about that! I assigned you now.