From 4d9d8d7b9c7cefb3ec873d5ff6361c7f2d19370e Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Mon, 18 Sep 2023 16:17:04 -0400 Subject: [PATCH] fix: fix error when model missing in transform command --- internal/authorizationmodel/read-from-input.go | 9 +++++---- internal/clierrors/clierrors.go | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/authorizationmodel/read-from-input.go b/internal/authorizationmodel/read-from-input.go index 2105c14..2ac3c76 100644 --- a/internal/authorizationmodel/read-from-input.go +++ b/internal/authorizationmodel/read-from-input.go @@ -23,6 +23,7 @@ import ( "path/filepath" "strings" + "github.com/openfga/cli/internal/clierrors" "github.com/spf13/cobra" ) @@ -71,9 +72,7 @@ func ReadFromInputFileOrArg( switch { case fileName != "": - if err = ReadFromFile(fileName, input, format, storeName); err != nil { - return err - } + return ReadFromFile(fileName, input, format, storeName) case len(args) > 0 && args[0] != "-": *input = args[0] // if the input format is set as the default, set it from the file extension (and default to fga) @@ -81,7 +80,9 @@ func ReadFromInputFileOrArg( *format = ModelFormatFGA } case !isOptional: - return cmd.Help() //nolint:wrapcheck + _ = cmd.Help() // print out the help message so users know what the command expects + + return fmt.Errorf("%w", clierrors.ErrModelInputMissing) } return nil diff --git a/internal/clierrors/clierrors.go b/internal/clierrors/clierrors.go index aea40fe..a9d52fc 100644 --- a/internal/clierrors/clierrors.go +++ b/internal/clierrors/clierrors.go @@ -27,6 +27,7 @@ var ( ErrInvalidFormat = errors.New("invalid format") ErrStoreNotFound = errors.New("store not found") ErrAuthorizationModelNotFound = errors.New("authorization model not found") + ErrModelInputMissing = errors.New("model input not provided") ) func ValidationError(op string, details string) error {