@@ -218,7 +218,7 @@ func (c *Config) getPackageConfigMap(ctx context.Context, packageName string) (m
218218
219219}
220220func (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 ()
222222
223223 if c .pkgConfigCache == nil {
224224 log .Debug ().Msg ("package cache is nil" )
@@ -228,11 +228,13 @@ func (c *Config) GetPackageConfig(ctx context.Context, packageName string) (*Con
228228 return pkgConf , nil
229229 }
230230
231- pkgConfig := reflect .New (reflect .ValueOf (c ).Elem ().Type ()).Interface ()
231+ //pkgConfig := reflect.New(reflect.ValueOf(c).Elem().Type()).Interface()
232+ pkgConfig := & Config {}
232233 if err := copier .Copy (pkgConfig , c ); err != nil {
233234 return nil , fmt .Errorf ("failed to copy config: %w" , err )
234235 }
235- pkgConfigTyped := pkgConfig .(* Config )
236+ //pkgConfigTyped := pkgConfig.(*Config)
237+ pkgConfigTyped := pkgConfig
236238
237239 configMap , err := c .getPackageConfigMap (ctx , packageName )
238240 if err != nil {
@@ -242,6 +244,7 @@ func (c *Config) GetPackageConfig(ctx context.Context, packageName string) (*Con
242244 configSection , ok := configMap ["config" ]
243245 if ! ok {
244246 log .Debug ().Msg ("config section not provided for package" )
247+ configMap ["config" ] = deepCopyConfigMap (c ._cfgAsMap )
245248 return pkgConfigTyped , nil
246249 }
247250
@@ -444,13 +447,13 @@ func (c *Config) addSubPkgConfig(ctx context.Context, subPkgPath string, parentP
444447 }
445448
446449 log .Debug ().Msg ("getting config" )
447- cfg , err := c .CfgAsMap (ctx )
450+ topLevelConfig , err := c .CfgAsMap (ctx )
448451 if err != nil {
449452 return fmt .Errorf ("failed to get configuration map: %w" , err )
450453 }
451454
452455 log .Debug ().Msg ("getting packages section" )
453- packagesSection := cfg ["packages" ].(map [string ]any )
456+ packagesSection := topLevelConfig ["packages" ].(map [string ]any )
454457
455458 // Don't overwrite any config that already exists
456459 _ , pkgExists := packagesSection [subPkgPath ]
@@ -600,18 +603,25 @@ func (c *Config) subPackages(
600603// recursive and recurses the file tree to find all sub-packages.
601604func (c * Config ) discoverRecursivePackages (ctx context.Context ) error {
602605 log := zerolog .Ctx (ctx )
606+ log .Trace ().Msg ("discovering recursive packages" )
603607 recursivePackages := map [string ]* Config {}
604608 packageList , err := c .GetPackages (ctx )
605609 if err != nil {
606610 return fmt .Errorf ("failed to get packages: %w" , err )
607611 }
608612 for _ , pkg := range packageList {
609613 pkgConfig , err := c .GetPackageConfig (ctx , pkg )
614+ pkgLog := log .With ().Str ("package" , pkg ).Logger ()
615+ pkgLog .Trace ().Msg ("iterating over package" )
610616 if err != nil {
611617 return fmt .Errorf ("failed to get package config: %w" , err )
612618 }
613619 if pkgConfig .Recursive {
620+ pkgLog .Trace ().Msg ("package marked as recursive" )
614621 recursivePackages [pkg ] = pkgConfig
622+ } else {
623+ pkgLog .Trace ().Msg ("package not marked as recursive" )
624+ pkgLog .Trace ().Msg (fmt .Sprintf ("%+v" , pkgConfig ))
615625 }
616626 }
617627 if len (recursivePackages ) == 0 {
@@ -703,8 +713,12 @@ func (c *Config) mergeInConfig(ctx context.Context) error {
703713
704714 configSectionUntyped , configExists := packageConfig ["config" ]
705715 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 )
708722 }
709723
710724 pkgLog .Trace ().Msg ("got config section for package" )
0 commit comments