Skip to content

Commit

Permalink
reformat the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
medmes committed Nov 28, 2024
1 parent b738211 commit 9e2cc08
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ func NewService(
func (s *Service) GenerateFile(out iotools.Out, path string, args types.KeyValueArgs) error {
fileExists, err := s.fileReader.FileExists(path)
if err != nil {
return fmt.Errorf("the path: '%s': %w: %w", path, ErrCheckingFileExistence, err)
return fmt.Errorf("the '%s' file path: %w: %w", path, ErrCheckingFileExistence, err)
}

if fileExists {
out.Write(fmt.Sprintf("the path: '%s' file already exists, reusing: '%s'\n", s.kind, path))
out.Write(fmt.Sprintf("the '%s' file path already exists, reusing: '%s'\n", s.kind, path))
return nil
}

err = s.fileGenerator.GenerateFile(out, path, args)
if err != nil {
return fmt.Errorf("the path: '%s': %w: %w", path, ErrGeneratingFile, err)
return fmt.Errorf("the '%s' file path: %w: %w", path, ErrGeneratingFile, err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_GenerateFile_Succeeds_WhenFileDoesAlreadyExist(t *testing.T) {

require.NoError(t, result)
require.Len(t, out.sink, 1)
assert.Equal(t, "the path: 'test-kind' file already exists, reusing: 'some-path'\n", out.sink[0])
assert.Equal(t, "the 'test-kind' file path already exists, reusing: 'some-path'\n", out.sink[0])
}

func Test_GenerateFile_ReturnsError_WhenFileGenerationReturnsError(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/service/scaffold/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (opts Options) validateDirectory() error {
fileInfo, err := os.Stat(opts.Directory)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("directory %s does not exist: %w: ", opts.Directory, commonerrors.ErrInvalidOption)
return fmt.Errorf("directory %s does not exist: %w:", opts.Directory, commonerrors.ErrInvalidOption)

Check failure on line 61 in internal/service/scaffold/options.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not end with punctuation or newlines (stylecheck)
}
return fmt.Errorf("failed to get directory info %s: %w: %w", opts.Directory, commonerrors.ErrInvalidOption, err)
}
Expand All @@ -72,15 +72,15 @@ func (opts Options) validateDirectory() error {

func (opts Options) validateModuleName() error {
if err := validation.ValidateModuleName(opts.ModuleName); err != nil {
return fmt.Errorf("module name: %w: %w", commonerrors.ErrInvalidOption, err)
return fmt.Errorf("opts.ModuleName: %w: %w", commonerrors.ErrInvalidOption, err)
}

return nil
}

func (opts Options) validateVersion() error {
if err := validation.ValidateModuleVersion(opts.ModuleVersion); err != nil {
return fmt.Errorf("module version: %w: %w", commonerrors.ErrInvalidOption, err)
return fmt.Errorf("opts.ModuleVersion: %w", err)
}

return nil
Expand Down

0 comments on commit 9e2cc08

Please sign in to comment.