Skip to content

Commit 52c9c25

Browse files
authored
Fix config issue with type conversion and deprecation warnings (#897)
* Fix config issue with type conversion Fixes #895. * Additional fix with deprecation warning
1 parent 0f55ecb commit 52c9c25

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

cmd/mockery.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ func (r *RootApp) Run() error {
232232
boilerplate = string(data)
233233
}
234234

235-
if r.Config.Packages == nil {
235+
configuredPackages, err := r.Config.GetPackages(ctx)
236+
if err != nil && !errors.Is(err, os.ErrNotExist) {
237+
return fmt.Errorf("failed to determine configured packages: %w", err)
238+
}
239+
if len(configuredPackages) == 0 {
236240
logging.WarnDeprecated(
237241
"packages",
238242
"use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
@@ -241,13 +245,7 @@ func (r *RootApp) Run() error {
241245
"migration": logging.DocsURL("/migrating_to_packages/"),
242246
},
243247
)
244-
}
245-
246-
configuredPackages, err := r.Config.GetPackages(ctx)
247-
if err != nil && !errors.Is(err, os.ErrNotExist) {
248-
return fmt.Errorf("failed to determine configured packages: %w", err)
249-
}
250-
if len(configuredPackages) != 0 {
248+
} else {
251249
r.Config.LogUnsupportedPackagesConfig(ctx)
252250

253251
configuredPackages, err := r.Config.GetPackages(ctx)

mockery-tools.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=v2.51.0
1+
VERSION=v2.51.1

pkg/config/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,14 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
502502
log.Trace().Msgf("parent-package config: %v", parentPkgConfig)
503503

504504
// Merge the parent config with the sub-package config.
505-
parentConfigSection := parentPkgConfig["config"].(map[string]any)
506-
subPkgConfigSection := subPkgConfig["config"].(map[string]any)
505+
parentConfigSection, ok := parentPkgConfig["config"].(map[string]any)
506+
if !ok {
507+
parentConfigSection = map[string]any{}
508+
}
509+
subPkgConfigSection, ok := subPkgConfig["config"].(map[string]any)
510+
if !ok {
511+
subPkgConfigSection = map[string]any{}
512+
}
507513
for key, val := range parentConfigSection {
508514
if _, keyInSubPkg := subPkgConfigSection[key]; !keyInSubPkg {
509515
subPkgConfigSection[key] = val

0 commit comments

Comments
 (0)