diff --git a/profile/database.go b/profile/database.go index 709aaa5a..07250356 100644 --- a/profile/database.go +++ b/profile/database.go @@ -131,12 +131,8 @@ func (h *databaseHook) PrePut(r record.Record) (record.Record, error) { // clean config config.CleanHierarchicalConfig(profile.Config) - // prepare config - err = profile.prepConfig() - if err != nil { - // error here, warning when loading - return nil, err - } + // prepare profile + profile.prepProfile() // parse config err = profile.parseConfig() diff --git a/profile/get.go b/profile/get.go index f2cb39b2..9d49b772 100644 --- a/profile/get.go +++ b/profile/get.go @@ -178,11 +178,8 @@ func prepProfile(r record.Record) (*Profile, error) { return nil, err } - // prepare config - err = profile.prepConfig() - if err != nil { - log.Errorf("profiles: profile %s has (partly) invalid configuration: %s", profile.ID, err) - } + // prepare profile + profile.prepProfile() // parse config err = profile.parseConfig() diff --git a/profile/profile.go b/profile/profile.go index dd7ae25f..1e126714 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -137,28 +137,27 @@ type Profile struct { //nolint:maligned // not worth the effort savedInternally bool } -func (profile *Profile) prepConfig() (err error) { +func (profile *Profile) prepProfile() { // prepare configuration - profile.configPerspective, err = config.NewPerspective(profile.Config) profile.outdated = abool.New() profile.lastActive = new(int64) - return } func (profile *Profile) parseConfig() error { - if profile.configPerspective == nil { - return errors.New("config not prepared") - } - - // check if already parsed + // Check if already parsed. if profile.dataParsed { return nil } + + // Create new perspective and marked as parsed. + var err error + profile.configPerspective, err = config.NewPerspective(profile.Config) + if err != nil { + return fmt.Errorf("failed to create config perspective: %w", err) + } profile.dataParsed = true - var err error var lastErr error - action, ok := profile.configPerspective.GetAsString(CfgOptionDefaultActionKey) profile.defaultAction = DefaultActionNotSet if ok { @@ -238,9 +237,7 @@ func New( profile.makeKey() // Prepare and parse initial profile config. - if err := profile.prepConfig(); err != nil { - log.Errorf("profile: failed to prep new profile: %s", err) - } + profile.prepProfile() if err := profile.parseConfig(); err != nil { log.Errorf("profile: failed to parse new profile: %s", err) }