diff --git a/protoc.go b/protoc.go index 26f4ce3..367ef64 100644 --- a/protoc.go +++ b/protoc.go @@ -54,9 +54,13 @@ func ValidProtobuf(filename string) (string, string, error) { scanner.Scan() line = scanner.Text() fields := strings.Fields(line) + if len(fields) < 2 { + noUuidExit(filename) + return "", "", fmt.Errorf("proto file does not have a UUID") + } // log.Info("GOT LINE", line) if fields[0] == "string" && fields[1] != "uuid" { - noUuid(filename) + noUuidExit(filename) return "", "", fmt.Errorf("proto file does not have a UUID") } // ok, uuid is here @@ -68,7 +72,7 @@ func ValidProtobuf(filename string) (string, string, error) { fields = strings.Fields(line) // log.Info("GOT LINE", line) if fields[0] == "string" && fields[1] != "version" { - noUuid(filename) + noUuidExit(filename) return "", "", fmt.Errorf("proto file does not have a version") } // found "version", the .proto file conforms @@ -77,11 +81,11 @@ func ValidProtobuf(filename string) (string, string, error) { return UUID, version, nil } // right now, noPluralMessage does os.Exit(-1) - // return "", "", noPluralMessage(filename) + noPluralMessageExit(filename) return "", "", fmt.Errorf("proto file does not have message %s", pluralBase) } -func noPluralMessage(filename string) { +func noPluralMessageExit(filename string) { filebase := strings.TrimSuffix(filename, ".proto") base := cases.Title(language.English, cases.NoLower).String(filebase) @@ -106,7 +110,7 @@ func noPluralMessage(filename string) { // repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s" // } -func noUuid(filename string) { +func noUuidExit(filename string) { filebase := strings.TrimSuffix(filename, ".proto") base := cases.Title(language.English, cases.NoLower).String(filebase) id := uuid.New()