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

Add boundserror when indexing into an invalid column #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iamed2
Copy link
Owner

@iamed2 iamed2 commented Dec 9, 2020

Fix #211

@c42f Is this a good enough error or do I need something better here? I wanted to use BoundsError but it's quite limited for display.

@c42f
Copy link
Contributor

c42f commented Dec 10, 2020

I think throwing any exception is a great improvement already, so I'd be happy with this.

Having said that, I think this error would be a bit mysterious to users as they're dealing with the column name in using getproperty, but the error emitted here has no mention of the column name:

julia> row = execute(conn, "select * from (values (1, 2), (3, 4)) as test (a,b)") |> first
LibPQ.Row(PostgreSQL result, 1)

julia> row.a
1

julia> row.x
ERROR: BoundsError: attempt to access 2-element Array{String,1} at index [0]
Stacktrace:
 [1] column_number at /home/ubuntu/.julia/dev/LibPQ/src/results.jl:481 [inlined]
 [2] getindex(::LibPQ.Result, ::Int64, ::Int64) at /home/ubuntu/.julia/dev/LibPQ/src/results.jl:509
 [3] getproperty(::LibPQ.Row, ::Symbol) at /home/ubuntu/.julia/dev/LibPQ/src/tables.jl:37
 [4] top-level scope at REPL[35]:1

A nice extension could be to add some @boundscheck logic to getproperty as well. I'm not sure what error type to throw though. It seems that the error type used for Base when accessing a nonexistent field of a type is ErrorException... which is nice and descriptive but nonspecific in the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LibPQ logs but doesn't throw for nonexistent column names
2 participants