diff options
Diffstat (limited to 'findFilename.go')
| -rw-r--r-- | findFilename.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/findFilename.go b/findFilename.go index 1b36f38..85ccbf4 100644 --- a/findFilename.go +++ b/findFilename.go @@ -1,12 +1,16 @@ package config import ( + "errors" "fmt" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" ) +var ErrProtoNoVarName error = errors.New("name not in .proto") +var ErrProtoVarNotString error = errors.New("name exists but is not a string") + // Gemini AI can help author some pretty good protobuf code. // I never remember the syntax for 'reflect' on these things. @@ -35,13 +39,13 @@ func GetFilename(pb proto.Message) (string, error) { // 4. Check if the field was found. If not, return false. if fieldDescriptor == nil { - return "", fmt.Errorf("fieldDescriptor == nil") + return "", ErrProtoNoVarName } // 5. (Optional but recommended) Verify the field is a string type. if fieldDescriptor.Kind() != protoreflect.StringKind { // The field exists but is not a string, so we can't return it as one. - return "", fmt.Errorf("The field exists but is not a string") + return "", ErrProtoVarNotString } // 6. If the field exists and is a string, get its value. |
