"exception error: no function clause matching" when query arguments not matching with execute args
Nobody has claimed this yet.
- Dominant language
- Gleam
- Stars
- 264
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
When I run the query in the program attached below I get an exception that seems to originate from Erlang.
```
gleam run
Compiling psqltest
Compiled in 0.18s
Running psqltest.main
exception error: no function clause matching
gleam_pgo_ffi:convert_error(badarg) (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/gleam_pgo_ffi.erl, line 71)
in function gleam_pgo_ffi:query/3 (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/gleam_pgo_ffi.erl, line 68)
in call from gleam@pgo:execute/4 (/Users/jaras/code/psqltest/build/dev/erlang/gleam_pgo/_gleam_artefacts/gleam@pgo.erl, line 193)
in call from psqltest:main/0 (/Users/jaras/code/psqltest/build/dev/erlang/psqltest/_gleam_artefacts/psqltest.erl, line 25)
```
the issue I found was that token and expires was swapped in the sql statement, when those were swapped back it worked as expected.
```gleam
import gleam/bit_array
import gleam/dynamic
import gleam/io
import gleam/pgo
pub fn main() {
let db =
pgo.connect(
pgo.Config(
..pgo.default_config(),
host: "localhost",
database: "gleam_test",
pool_size: 10,
),
)
let sql =
"INSERT INTO sessions (user_id, token, expires) VALUES ($1, $2, $3) RETURNING id"
let result =
pgo.execute(
sql,
db,
[
pgo.int(3),
pgo.timestamp(#(#(1, 2, 3), #(4, 5, 6))),
pgo.bytea(bit_array.from_string("token")),
],
dynamic.element(0, dynamic.int),
)
io.debug(result)
}
```
```sql
-- auto-generated definition
CREATE TABLE sessions
(
id bigserial
PRIMARY KEY,
token bytea NOT NULL
UNIQUE,
user_id integer NOT NULL,
expires timestamp WITH TIME ZONE DEFAULT NOW() NOT NULL
);
ALTER TABLE sessions
OWNER TO dkjanras;
CREATE INDEX sessions_token_index
ON sessions (token);
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the mismatch through pgo.execute/4 using the provided Gleam program and SQL schema. Inspect gleam_pgo_ffi:query/3 and convert_error/1 around the generated FFI lines 68-71. Done should mean this invalid argument combination reports a useful database or query error instead of an Erlang function-clause exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- erlang, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100