stargate / data-api

JSON document API for Apache Cassandra (formerly known as JSON API)
https://stargate.io
Apache License 2.0
14 stars 16 forks source link

Improve the error for commands that are not supported on tables, and table commands not on collections #1692

Closed amorton closed 1 week ago

amorton commented 1 week ago

Send this to a table

{
  "updateMany": {
      "filter" : {},
      "update": {}
}}

Get this back

{
    "errors": [
        {
            "message": "Server internal error: UpdateManyCommand Command does not support operating on Tables, target was SchemaObjectName[keyspace=demo, table=collections]",
            "errorCode": "SERVER_INTERNAL_ERROR",
            "id": "ee5c2ae9-3731-4379-926b-e979e22de6b5",
            "title": "Server internal error",
            "family": "SERVER",
            "scope": "EMPTY"
        }
    ]
}

This is handled in the CommandResolver interface with defaults so easy to change all in one place

bonus points if the error is specific for tables or collections and can list all the commands that are supported for each by iterating an enum or such

amorton commented 1 week ago

claiming this guy as an easy ticket to bang out with limited time

amorton commented 1 week ago

Improved error for a command against a table:

{
    "errors": [
        {
            "message": "The command is not supported by Tables in the API.  \n\nWhile many commands operate on both Tables and Collections, some commands can only be run against Tables or Collections. \n\nThe commands supported by tables are: alterTable, createIndex, createVectorIndex, deleteMany, deleteOne, find, findOne, insertMany, insertOne, listIndexes, updateOne.\nThe commands supported by collections are: countDocuments, deleteMany, deleteOne, estimatedDocumentCount, find, findOne, findOneAndDelete, findOneAndReplace, findOneAndUpdate, insertMany, insertOne, updateMany, updateOne.\n\nThe unsupported command ran against the table: demo.users\nThe unsupported command was: updateMany.\n\nResend using one of the supported commands.",
            "scope": "",
            "errorCode": "UNSUPPORTED_TABLE_COMMAND",
            "id": "a4623d40-bb14-4213-9cff-c959bd9d9a94",
            "family": "REQUEST",
            "title": "Commands is not supported by Tables"
        }
    ]
}

message text

The command is not supported by Tables in the API.  

While many commands operate on both Tables and Collections, some commands can only be run against Tables or Collections. 

The commands supported by tables are: alterTable, createIndex, createVectorIndex, deleteMany, deleteOne, find, findOne, insertMany, insertOne, listIndexes, updateOne.
The commands supported by collections are: countDocuments, deleteMany, deleteOne, estimatedDocumentCount, find, findOne, findOneAndDelete, findOneAndReplace, findOneAndUpdate, insertMany, insertOne, updateMany, updateOne.

The unsupported command ran against the table: demo.users
The unsupported command was: updateMany.

Resend using one of the supported commands.

Example for unsupported by Collection

{
    "errors": [
        {
            "message": "The command is not supported by Collections in the API.  \n\nWhile many commands operate on both Tables and Collections, some commands can only be run against Tables or Collections. \n\nThe commands supported by collections are: countDocuments, deleteMany, deleteOne, estimatedDocumentCount, find, findOne, findOneAndDelete, findOneAndReplace, findOneAndUpdate, insertMany, insertOne, updateMany, updateOne.\nThe commands supported by tables are: alterTable, createIndex, createVectorIndex, deleteMany, deleteOne, find, findOne, insertMany, insertOne, listIndexes, updateOne.\n\n\nThe unsupported command ran against the collection: demo.users2\nThe unsupported command was: listIndexes.\n\nResend using one of the supported commands. ",
            "scope": "",
            "errorCode": "UNSUPPORTED_COLLECTION_COMMAND",
            "id": "fece46cb-cfe5-43a1-8bdb-23666d8fd0fe",
            "family": "REQUEST",
            "title": "Commands is not supported by Collections"
        }
    ]
}

message text - not deliberate that the "commands supported by" lists collections first this time

The command is not supported by Collections in the API.  

While many commands operate on both Tables and Collections, some commands can only be run against Tables or Collections. 

The commands supported by collections are: countDocuments, deleteMany, deleteOne, estimatedDocumentCount, find, findOne, findOneAndDelete, findOneAndReplace, findOneAndUpdate, insertMany, insertOne, updateMany, updateOne.
The commands supported by tables are: alterTable, createIndex, createVectorIndex, deleteMany, deleteOne, find, findOne, insertMany, insertOne, listIndexes, updateOne.

The unsupported command ran against the collection: demo.users2
The unsupported command was: listIndexes.

Resend using one of the supported commands.