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

Improves logging for unknown bblfsh driver in parse cmd #186

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

se7entyse7en
Copy link
Contributor

@se7entyse7en se7entyse7en commented Jan 2, 2019

Closes #163.

@se7entyse7en se7entyse7en force-pushed the better-err-message-unknown-driver branch from b841fbb to 11a61d4 Compare January 2, 2019 12:17
@se7entyse7en se7entyse7en requested a review from a team January 2, 2019 12:17
Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

LGTM but some cosmetic things that could (or should, idk) be addressed.

I see that this PR adds some useful info to the logged error, and it's nice; nevertheless, I do not know what @carlosms required when he opened src-d/sourced-ce#163 because he only said:

the error could be more user-friendly

I'd expect more details about how to make the log more user-friendly, and how this PR helps in that direction.

cmd/srcd/cmd/parse.go Show resolved Hide resolved
cmd/srcd/cmd/parse.go Show resolved Hide resolved
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()

res, err := client.Parse(ctx, &api.ParseRequest{
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it is needed to wrap the original error as returned by client.Parse; if it is not, we could just do:

Suggested change
res, err := client.Parse(ctx, &api.ParseRequest{
return client.Parse(ctx, &api.ParseRequest{

and get rid of the error checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I don't know the type of error message thrown by the Parse method, so I cannot say whether writing server error gives some more context.

Copy link
Contributor

Choose a reason for hiding this comment

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

related to src-d/sourced-ce#186 (comment)

I saw that how we use parseLang is with:

lang, err = parseLang(ctx, c, path, b)
if err != nil {
    return fmt.Errorf("cannot parse language: %v", err)
}

and in parseLang:

func parseLang(ctx context.Context, client api.EngineClient, path string, b []byte) (string, error) {
    // ...
    res, err := client.Parse(ctx, &api.ParseRequest{})
    if err != nil {
        return "", fmt.Errorf("server error: %v", err)
    }
    return res.Lang, nil
}

so imo parseLang is not handling the error, nor dealing with different error types, nor adding any other valuable info but an extra server error string. In that situation I think it's better to return the same error, and let the caller to decide how it's already doing.

Copy link
Contributor Author

@se7entyse7en se7entyse7en Jan 2, 2019

Choose a reason for hiding this comment

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

What I meant is that the string server error: <error> may give the user the idea that the type of error is due to some functionality that went wrong during a client-server communication. I don't know if the user might be interested in this kind of information.

I'm thinking about an error such as permission denied. In that case reading cannot parse language: server error: permission denied IMO let the user infer that there's some sort of communication that went wrong. On the other hand simply reading cannot parse language: permission denied might be more cryptic. Again I don't know what type of errors client.Parse may raise, maybe adding the extra server error: string is actually non-necessary and redundant.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with the string; my point is that imo wrapping the error with new strings from every function it crosses, can be wrong.
But it's just an internal feeling, so not a strong opinion in this case ;)

cmd/srcd/cmd/parse.go Outdated Show resolved Hide resolved
cmd/srcd/cmd/parse.go Show resolved Hide resolved
cmd/srcd/cmd/parse.go Outdated Show resolved Hide resolved
@se7entyse7en se7entyse7en force-pushed the better-err-message-unknown-driver branch from 11a61d4 to 232c2a3 Compare January 2, 2019 14:41
cmd/srcd/cmd/parse.go Outdated Show resolved Hide resolved
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
@se7entyse7en se7entyse7en force-pushed the better-err-message-unknown-driver branch from 232c2a3 to 8e222c2 Compare January 2, 2019 18:35
@@ -79,6 +81,24 @@ The remaining nodes are printed to standard output in JSON format.`,
return err
}

if lang == "" {
lang, err = parseLang(ctx, c, path, b)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should use parse method of bblfsh file just to get the language of it.
I would better call enry here directly.

Or kept as it was before but check for ErrMissingDriver if bblfsh exports it. (if not, I think we can create an issue to bblfsh).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that currently when the --lang flag is provided the language detection is skipped and performed otherwise, the idea is perform the language detection as a separate step in order to check whether the language is supported. Other than that I don't know which is the best solution for achieving this, and maybe enry (which I don't know) is actually the best option. I used bblfsh just because the logic was already present.

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'm gonna check that ErrMissingDriver error.

Copy link
Contributor Author

@se7entyse7en se7entyse7en Jan 4, 2019

Choose a reason for hiding this comment

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

It seems that by simply checking whether the error thrown is of type ErrMissingDriver this PR could be simplified a lot. I'm just trying to understand this error that I encountered when importing bblfshd.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to import bblfshd. The error should be exported in client-go. If it's not, I think we can request it. The use case for treating this error differently from just "internal error" is common in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIU the only errors exported by client-go are these. Actually I think that this shouldn't be an internal error too as you said. I'm gonna open the issue requesting this then.

if err != nil {
return fmt.Errorf("server error: %v", err)
return fmt.Errorf("cannot parse language: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

huh? You parse a file here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I meant is that it cannot parse the language from the file. Do you think that "cannot parse language from given file: %v" or "cannot parse file: %v" is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, wait. It's my bad. The context was collapsed on GH and I misunderstood it. All fine. Thanks!

Copy link
Contributor

@smacker smacker left a comment

Choose a reason for hiding this comment

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

If client-go exports ErrMissingDriver we can do it better but for now it looks good enough for me 👍

Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

Since src-d/sourced-ce#186 (comment) is not a strong opinion, and the rest of the comments were already addressed, LGTM

@se7entyse7en se7entyse7en merged commit a77ba65 into master Jan 8, 2019
@se7entyse7en se7entyse7en deleted the better-err-message-unknown-driver branch January 8, 2019 09:53
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.

3 participants