sqld icon indicating copy to clipboard operation
sqld copied to clipboard

sqld http connection wrong error response sometimes

Open luisfvieirasilva opened this issue 2 years ago • 7 comments
trafficstars

Inconsistent error return using http connection

When sending an invalid statement as request:

{
    "statements": [
        {
            "q": "select"
        }
    ]
}

sqld returns an object with the error: {"error":"unexpected end of input at (1, 7)"}

But there are cases where it returns an array of objects

First case

Given a table created with following commands:

→  create table foo (id primary key);
→  create table bar (id integer, foreign key(id) references foo(id));

→  insert into foo (id) values (0);
→
→  insert into bar (id) values (0)

When doing a drop table request:

{
    "statements": [
        {
            "q": "drop table foo;"
        }
    ]
}

sqld returns (an array of objects) [ { "error": "FOREIGN KEY constraint failed" } ]

Second case

Creating an table that already exists. Request:

{
    "statements": [
        {
            "q": "CREATE TABLE users (email TEXT);"
        }
    ]
}

returned error: [ { "error": "table users already exists in CREATE TABLE users (email TEXT); at offset 13" }]

luisfvieirasilva avatar Jun 07 '23 20:06 luisfvieirasilva

This raises the question: how long are we going to support the old v0 HTTP API that we really aren't going to use in the future for client SDKs? At some point it will become a maintenance drag, and add very little to the value of the product.

CodingDoug avatar Jun 07 '23 20:06 CodingDoug

@CodingDoug Good point! New information about this: The requests that are with wrong responses is returning 200 status code. So the inconsistency is with the way we return error on valid request. libsql-client-go is expecting an success body to be like this:

httpResults:
  - results: resultSet
  - error:
      - message: string

But sqld is returning this:

httpResults:
  - results: resultSet
  - error: string

luisfvieirasilva avatar Jun 07 '23 20:06 luisfvieirasilva

I think we can get rid of the legacy HTTP endpoint

MarinPostma avatar Jun 08 '23 10:06 MarinPostma

I think we can get rid of the legacy HTTP endpoint

Looks like it's still in use here: https://github.com/libsql/libsql-client-java

Don't know if anyone is using it. @penberg @MarinPostma

CodingDoug avatar Jun 08 '23 13:06 CodingDoug

@penberg is is worth migrating the java client to the new API?

MarinPostma avatar Jun 08 '23 13:06 MarinPostma

@penberg is is worth migrating the java client to the new API?

I think we should migrate the java client. FYI @penberg

haaawk avatar Jul 02 '23 09:07 haaawk

@haaawk @penberg What is the status on that?

MarinPostma avatar Aug 28 '23 13:08 MarinPostma