Go error messages not helpful

Hi,

Go sometimes doesn’t know the right line number. When it does compilation, most of the time it tells me the correct number of the line that contains an error.

But sometimes it doesn’t, and I have no idea why. There are two problems I get. Go tells me the wrong line number, off by 1. Or: Go only knows only the line number of the opening brace of a function call.

When I have these sorts of problems, usually, I think, it’s when my code calls a function that resides in a package. And the error is usually that I passed an argument that has the wrong type.

And when there are very few arguments that’s okay, but not so when the functions take many arguments. And another thing is that Go never tells me the number of the argument - which is what other compilers usually do, don’t they?

I can’t give an example. It happens every day or week, and I could give an example, but you must have noticed that there is something a bit wrong with Go in this regard?

The very least solution would be trying to tell the user the number of the argument that has the wrong type.

Thanks, Kind regards

Do you mean in a situation like this: https://play.golang.org/p/RBrlfV41adh You’d prefer to see line 21 indicated as an error instead of line 18?

Yep, pretty much like this. Thanks for clarifying it. :slightly_smiling_face:

PS: In my case today I had passed two nils, so, Go naming the argument didn’t help.

And for some reason the line number was the line containing the function name, a few lines above. Maybe Go has some trouble with line numbers when there are several errors.

I have tried to reproduce the problem.

So, the problem with two same arguments (c,c,nil,nil,0,0 etc) is, that without getting told which one it is, you need to rely on the line number. That is one issue.

And the line number is off by 1, or by 2, or it’s the line with the function name as in your example. But I never know what the line number will be, so it’s a bit of a guessing game. I wonder if they have any bug filed related to this.

off by two lines
https://play.golang.org/p/wXI3m-iO9f7

off by one line
https://play.golang.org/p/pbISInXKqch

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.