Skip to content

Commit

Permalink
Fix config issue with type conversion and deprecation warnings (#897)
Browse files Browse the repository at this point in the history
* Fix config issue with type conversion

Fixes #895.

* Additional fix with deprecation warning
  • Loading branch information
LandonTClipp authored Jan 20, 2025
1 parent 0f55ecb commit 52c9c25
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 6 additions & 8 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ func (r *RootApp) Run() error {
boilerplate = string(data)
}

if r.Config.Packages == nil {
configuredPackages, err := r.Config.GetPackages(ctx)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("failed to determine configured packages: %w", err)
}
if len(configuredPackages) == 0 {
logging.WarnDeprecated(
"packages",
"use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
Expand All @@ -241,13 +245,7 @@ func (r *RootApp) Run() error {
"migration": logging.DocsURL("/migrating_to_packages/"),
},
)
}

configuredPackages, err := r.Config.GetPackages(ctx)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("failed to determine configured packages: %w", err)
}
if len(configuredPackages) != 0 {
} else {
r.Config.LogUnsupportedPackagesConfig(ctx)

configuredPackages, err := r.Config.GetPackages(ctx)
Expand Down
2 changes: 1 addition & 1 deletion mockery-tools.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=v2.51.0
VERSION=v2.51.1
10 changes: 8 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,14 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
log.Trace().Msgf("parent-package config: %v", parentPkgConfig)

// Merge the parent config with the sub-package config.
parentConfigSection := parentPkgConfig["config"].(map[string]any)
subPkgConfigSection := subPkgConfig["config"].(map[string]any)
parentConfigSection, ok := parentPkgConfig["config"].(map[string]any)
if !ok {
parentConfigSection = map[string]any{}
}
subPkgConfigSection, ok := subPkgConfig["config"].(map[string]any)
if !ok {
subPkgConfigSection = map[string]any{}
}
for key, val := range parentConfigSection {
if _, keyInSubPkg := subPkgConfigSection[key]; !keyInSubPkg {
subPkgConfigSection[key] = val
Expand Down

0 comments on commit 52c9c25

Please sign in to comment.