@@ -218,7 +218,7 @@ func (c *Config) getPackageConfigMap(ctx context.Context, packageName string) (m
218
218
219
219
}
220
220
func (c * Config ) GetPackageConfig (ctx context.Context , packageName string ) (* Config , error ) {
221
- log := zerolog .Ctx (ctx )
221
+ log := zerolog .Ctx (ctx ). With (). Str ( "package-path" , packageName ). Logger ()
222
222
223
223
if c .pkgConfigCache == nil {
224
224
log .Debug ().Msg ("package cache is nil" )
@@ -228,11 +228,13 @@ func (c *Config) GetPackageConfig(ctx context.Context, packageName string) (*Con
228
228
return pkgConf , nil
229
229
}
230
230
231
- pkgConfig := reflect .New (reflect .ValueOf (c ).Elem ().Type ()).Interface ()
231
+ //pkgConfig := reflect.New(reflect.ValueOf(c).Elem().Type()).Interface()
232
+ pkgConfig := & Config {}
232
233
if err := copier .Copy (pkgConfig , c ); err != nil {
233
234
return nil , fmt .Errorf ("failed to copy config: %w" , err )
234
235
}
235
- pkgConfigTyped := pkgConfig .(* Config )
236
+ //pkgConfigTyped := pkgConfig.(*Config)
237
+ pkgConfigTyped := pkgConfig
236
238
237
239
configMap , err := c .getPackageConfigMap (ctx , packageName )
238
240
if err != nil {
@@ -242,6 +244,7 @@ func (c *Config) GetPackageConfig(ctx context.Context, packageName string) (*Con
242
244
configSection , ok := configMap ["config" ]
243
245
if ! ok {
244
246
log .Debug ().Msg ("config section not provided for package" )
247
+ configMap ["config" ] = deepCopyConfigMap (c ._cfgAsMap )
245
248
return pkgConfigTyped , nil
246
249
}
247
250
@@ -444,13 +447,13 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
444
447
}
445
448
446
449
log .Debug ().Msg ("getting config" )
447
- cfg , err := c .CfgAsMap (ctx )
450
+ topLevelConfig , err := c .CfgAsMap (ctx )
448
451
if err != nil {
449
452
return fmt .Errorf ("failed to get configuration map: %w" , err )
450
453
}
451
454
452
455
log .Debug ().Msg ("getting packages section" )
453
- packagesSection := cfg ["packages" ].(map [string ]any )
456
+ packagesSection := topLevelConfig ["packages" ].(map [string ]any )
454
457
455
458
// Don't overwrite any config that already exists
456
459
_ , pkgExists := packagesSection [subPkgPath ]
@@ -600,18 +603,25 @@ func (c *Config) subPackages(
600
603
// recursive and recurses the file tree to find all sub-packages.
601
604
func (c * Config ) discoverRecursivePackages (ctx context.Context ) error {
602
605
log := zerolog .Ctx (ctx )
606
+ log .Trace ().Msg ("discovering recursive packages" )
603
607
recursivePackages := map [string ]* Config {}
604
608
packageList , err := c .GetPackages (ctx )
605
609
if err != nil {
606
610
return fmt .Errorf ("failed to get packages: %w" , err )
607
611
}
608
612
for _ , pkg := range packageList {
609
613
pkgConfig , err := c .GetPackageConfig (ctx , pkg )
614
+ pkgLog := log .With ().Str ("package" , pkg ).Logger ()
615
+ pkgLog .Trace ().Msg ("iterating over package" )
610
616
if err != nil {
611
617
return fmt .Errorf ("failed to get package config: %w" , err )
612
618
}
613
619
if pkgConfig .Recursive {
620
+ pkgLog .Trace ().Msg ("package marked as recursive" )
614
621
recursivePackages [pkg ] = pkgConfig
622
+ } else {
623
+ pkgLog .Trace ().Msg ("package not marked as recursive" )
624
+ pkgLog .Trace ().Msg (fmt .Sprintf ("%+v" , pkgConfig ))
615
625
}
616
626
}
617
627
if len (recursivePackages ) == 0 {
@@ -703,8 +713,12 @@ func (c *Config) mergeInConfig(ctx context.Context) error {
703
713
704
714
configSectionUntyped , configExists := packageConfig ["config" ]
705
715
if ! configExists {
706
- pkgLog .Trace ().Msg ("config section doesn't exist, setting it to a deepcopy of the top-level config" )
707
- packageConfig ["config" ] = deepCopyConfigMap (defaultCfg )
716
+ // The reason why this should never happen is because getPackageConfigMap
717
+ // should be populating the config section with the top-level config if it
718
+ // wasn't defined in the yaml.
719
+ msg := "config section does not exist for package, this should never happen"
720
+ pkgLog .Error ().Msg (msg )
721
+ return fmt .Errorf (msg )
708
722
}
709
723
710
724
pkgLog .Trace ().Msg ("got config section for package" )
0 commit comments