Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[examples/ktor] Inserting the same sighting twice causes HTTP 500 error #64

Open
stuebingerb opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@stuebingerb
Copy link
Owner

stuebingerb commented Nov 8, 2024

To reproduce, execute the following mutation twice against the ktor example:

mutation {
  createUFOSighting(
    input: {
      country: { city: "", comments: "", country: "", state: "" }
      date: "2024-01-01"
      duration: 1.5
      latitude: 1.5
      longitude: 1.5
      shape: ""
    }
  ) {
    id
  }
}

First one returns the expected id:

{
  "data": {
    "createUFOSighting": {
      "id": 9299
    }
  }
}

Second one returns an HTTP 500 error due to a unique constraint violation on the data:

Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Eindeutiger Index oder Primärschlüssel verletzt: "PUBLIC.IDX_UFOSIGHTING_UNIQUE_INDEX_8 ON PUBLIC.UFOSIGHTINGS(SEEING_AT, CITY, STATE, COUNTRY, SHAPE, DURATION, COMMENTS) VALUES 9299"

Expectation:
There must not be an HTTP 500 response but a proper GraphQLError

The unique index violation seems to be intentional, albeit arguable.

@stuebingerb stuebingerb changed the title [examples/ktor] Inserting the same Sighting twice causes HTTP 500 error [examples/ktor] Inserting the same sighting twice causes HTTP 500 error Nov 8, 2024
@stuebingerb stuebingerb added the bug Something isn't working label Nov 8, 2024
@stuebingerb
Copy link
Owner Author

stuebingerb commented Nov 8, 2024

I can see the exception being wrapped in ParallelRequestExecutor but the result of schema.execute is still the original (unwrapped) exception. I believe the wrapped exception is swallowed in internal suspend fun <T, R> Collection<T>.toMapAsync:

    val jobs = map { item ->
        launch(dispatcher) {
            try {
                val res = block(item)
                channel.send(item to res)
            } catch (e: Exception) {
                channel.close(e)
            }
        }
    }

Not yet sure where the unwrapped exception then comes from, especially seeing some tests work as expected.

@stuebingerb
Copy link
Owner Author

stuebingerb commented Nov 11, 2024

Looks like some tests actually expect schema.execute to throw unwrapped exceptions. Not sure how this was supposed to work. It is also a bit confusing to see exceptions being caught in a code block commented with "exceptions are not caught on purpose to pass up business logic errors". This might be a bigger issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant