Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

fix error handling example #53

Merged
merged 1 commit into from
Jun 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions user/server-grpc-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/bblfsh/sdk/protocol"
Expand All @@ -135,6 +136,7 @@ func main() {
if err != nil {
os.Exit(1)
}

client := protocol.NewProtocolServiceClient(conn)
req := &protocol.ParseUASTRequest{Filename: "hello.py",
Content: "print('hello world!')",
Expand All @@ -144,6 +146,12 @@ func main() {
if err != nil {
os.Exit(1)
}

if resp.Status != protocol.Ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this example is for illustrative purposes, it may be interesting to add an error message per error to better explain what the problem is. In this case something like
Source code has not been parsed correctly, or similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated it to include an error message, also making it explicit that resp.Errors might contain multiple errors.

fmt.Println("Parsing errors:", strings.Join(resp.Errors))
os.Exit(1)
}

printTokens(resp.UAST)
}

Expand Down