Skip to content

Exception when calling SortedSetRemoveAsync on IDatabase with empty values array #1972

Closed

Description

@olizarevichroman

I'm getting an exception (ERR wrong number of arguments for 'zrem' command) when calling database.SortedSetRemoveAsync(setKey, values) where "values" is empty array.

As a result the same call within a transaction also throws an exception, but with less descriptive message (EXECABORT Transaction discarded because of previous errors.)

It seems like such command might be considered as always successful.

Package version "2.2.88"

Activity

  1. hankovich commented on Jan 31, 2022

    @hankovich
    Contributor

    I've inspected all IDatabase's methods and found several which don't handle empty collections gracefully (i.e. will throw).

    Here's the complete list (and don't forget about all Async versions):

    GeoAdd
    GeoHash
    GeoPosition
    
    HyperLogLogLength
    HyperLogLogMerge
    
    KeyExists
    
    SetCombine
    SetCombineAndStore
    
    SortedSetCombineAndStore
    SortedSetRemove
    
    StreamAcknowledge (*)
    StreamAdd (*)
    StreamClaim (*)
    StreamClaimIdsOnly (*)
    StreamDelete
    StreamRead (*)
    StreamReadGroup (*)
    

    Methods which are not marked with (*) will throw ERR wrong number of arguments for 'COMMANDNAME' command.

    Methods which are marked with (*) have explicit throw new ArgumentOutOfRangeException(...) for empty collections, so they differ from the others.

    However, I think that they can be converted to act as no-op to be consistent with other methods which handle empty arrays gracefully. At least it doesn't make sense to throw ArgumentOutOfRangeException, because there's no range. It should have been just ArgumentException. I understand that it's not always possible not to throw exceptions (or throw exception of another type) because of compatibility reasons. Just thoughts.

  2. NickCraver commented on Jan 31, 2022

    @NickCraver
    Collaborator

    I have some large PRs in pipe around normalizing docs and such, so this would wait until after, but I think it's reasonable to put a similar check in here for .Length == 0 => default like we do in other places. That should be a net win without breaking anyone. Thoughts?

  3. mgravell commented on Aug 25, 2026

    @mgravell
    Collaborator

    Closed by #3192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions