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

returned an error each time something bad occurred. #190

Closed
wants to merge 1 commit into from
Closed

returned an error each time something bad occurred. #190

wants to merge 1 commit into from

Conversation

Nexucis
Copy link
Contributor

@Nexucis Nexucis commented Jul 17, 2020

fix #189

now it returns an http error 500.

I suppose we should type the error coming from the cache to associate them to a better HTTP error code

@Nexucis
Copy link
Contributor Author

Nexucis commented Jul 17, 2020

ah that's a weird error . Interesting ...

It's returns now the following error :

image

It seems that the code returned doesn't match the error message.

location, err := s.cache.Find(&params.TextDocumentPositionParams)
if err != nil {
return nil, nil
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's incorrect.

See #185 for why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get why we couldn't return an error saying the document is not there. In the point of view of the cache that's an error.

It should be on the side of the caller to decide what to do with it using a sort of switch case on the error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't suppress errors about documents being not there. In fact this error shouldn't have happened in the first place.

The only type of error that should be suppressed is, if the document context has expired, since in that case the request is silently cancelled to avoid returning outdated results to the client.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For explanation: An expired document context means, the document content has changed while processing the request. While that's rare, it shouldn't result in an error. However in that case, an error is raised internally, since the request can't be handled in a sane way. These special errors have to be filtered out, before responding to the client.

@slrtbtfs
Copy link
Member

ah that's a weird error . Interesting ...

How did you get that error?

For the example from the issue, I now get the correct response:

curl -XPOST http://localhost:8080/completion -d '{"expr":"sum ", "limit": 100, "positionChar": 4, "positionLine": 0}'

The error code is a 500, though. 400 would be better.

@slrtbtfs
Copy link
Member

Btw, you can ignore the test failure raised by the CI for now. It will be fixed as part of #181 .

@Nexucis
Copy link
Contributor Author

Nexucis commented Jul 17, 2020

How did you get that error?

ah sorry, I was talking about the error in the CI

For the example from the issue, I now get the correct response:

Well yes since I'm returning systematically an error if the document is empty, then it fixed the current issue.
And yes I'm agree returning an error 400 would make more sense. And for that it will require to make a switch case on the jsonrpc error.

}

call, ok := location.Node.(*promql.Call)
if !ok {
return nil, nil
return nil, errors.New("no node find for the given query")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code branch is not an error condition. In case we reach this, the cursor is not over a function call and we simply return an empty result.

Also note, that returning nil pointers isn't a problem with this endpoint, since no member accesses take place.

@slrtbtfs
Copy link
Member

And yes I'm agree returning an error 400 would make more sense. And for that it will require to make a switch case on the jsonrpc error.

A switch case would make to many assumptions about the cache package behaviour.

IMO, the easiest option would be to only return 500 on panics.

@Nexucis Nexucis marked this pull request as draft July 17, 2020 19:29
@slrtbtfs
Copy link
Member

Can we split this into two PRs?

@Nexucis
Copy link
Contributor Author

Nexucis commented Jul 17, 2020

sure no issue. Even more, if you want to do it on yourside, we can decline this PR. I don't mind at all ;). Doesn't look like it will be a quick fix so for sure I won't have the time to do it before some times. But maybe it's just me that will certainly go a bit too far hahaha.

@Nexucis
Copy link
Contributor Author

Nexucis commented Jul 19, 2020

I'm declining this PR for the following reason:

  • scope has been changed
  • I won't have the time to work on it before couple of times, so if someone would like to fix it, then this PR shouldn't be a blocker
  • should be splitted into two separated PR

@Nexucis Nexucis closed this Jul 19, 2020
@Nexucis Nexucis deleted the bugfix/error-returned branch July 19, 2020 11:31
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.

Unexpected dead of HTTP request for completion endpoint
2 participants