Skip to content

Commit

Permalink
Merge pull request #107 from timburks/master
Browse files Browse the repository at this point in the history
Update apps/report sample to report better errors for non-OpenAPIv2 input.
  • Loading branch information
timburks authored Jan 17, 2019
2 parents d48bb90 + a2d7f3f commit d55a06a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions apps/report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/golang/protobuf/proto"
Expand All @@ -28,18 +29,17 @@ import (
pb "github.com/googleapis/gnostic/OpenAPIv2"
)

func readDocumentFromFileWithName(filename string) *pb.Document {
func readDocumentFromFileWithName(filename string) (*pb.Document, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Printf("File error: %v\n", err)
os.Exit(1)
return nil, err
}
document := &pb.Document{}
err = proto.Unmarshal(data, document)
if err != nil {
panic(err)
return nil, err
}
return document
return document, nil
}

func printDocument(code *printer.Code, document *pb.Document) {
Expand Down Expand Up @@ -229,8 +229,12 @@ func main() {
return
}

document := readDocumentFromFileWithName(args[0])
document, err := readDocumentFromFileWithName(args[0])

if err != nil {
log.Printf("Error reading %s. This sample expects OpenAPI v2.", args[0])
os.Exit(-1)
}
code := &printer.Code{}
code.Print("API REPORT")
code.Print("----------")
Expand Down

0 comments on commit d55a06a

Please sign in to comment.