diff --git a/change-handler.go b/change-handler.go index 721a745dcd992ff702fdbff31f0b9ce6046ee9d4..65682150f885acb4f3aefe6c31276d349d12ed7f 100644 --- a/change-handler.go +++ b/change-handler.go @@ -22,13 +22,13 @@ func (s *Settings[C]) OnChange(hook ChangeHook) *Settings[C] { } // HasOnChangeHook returns true if there are registered hooks. -func (s *Settings[C]) HasOnChangeHook(hook ChangeHook) *Settings[C] { +func (s *Settings[C]) HasOnChangeHook(hook ChangeHook) bool { for _, h := range s.hooks.change { if h == hook { - break + return true } } - return s + return false } // RemoveOnChangeHook removes a change hook from the list of hooks. diff --git a/error-handler.go b/error-handler.go index 92af915e1cf0f3fe236ea150f4ebf74c52865aa6..ebcb52c04499998423dc5e987888eefe92af5456 100644 --- a/error-handler.go +++ b/error-handler.go @@ -18,13 +18,13 @@ func (s *Settings[C]) OnError(hook ErrorHook) *Settings[C] { } // HasOnErrorHook returns true if there are registered hooks. -func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) *Settings[C] { +func (s *Settings[C]) HasOnErrorHook(hook ErrorHook) bool { for _, h := range s.hooks.error { if h == hook { - break + return true } } - return s + return false } // RemoveOnErrorHook removes a change hook from the list of hooks. @@ -39,8 +39,23 @@ func (s *Settings[C]) RemoveOnErrorHook(hook ErrorHook) *Settings[C] { } func (s *Settings[C]) notifyErrorHooks() *Settings[C] { + + if len(s.errors) == 0 { + return s + } + + if len(s.hooks.error) == 0 { + return s + } + + errors := make([]error, len(s.errors)) + copy(errors, s.Errors()) + s.ResetErrors() + for _, h := range s.hooks.error { - go h.Handle(ErrorEvent{}) + go h.Handle(ErrorEvent{ + Errors: errors, + }) } return s } diff --git a/error.go b/error.go index 4ee39a6b7cb8e19fe700acfed43b7376df4d9526..d097951432905a8888f2601b30ccbed5cb054752 100644 --- a/error.go +++ b/error.go @@ -8,14 +8,14 @@ import ( "reflect" ) -// ResetError is used to reset the error to nil +// ResetErrors is used to reset the error to nil // After calling this function, the call HasErrors() will return false func (s *Settings[C]) ResetErrors() *Settings[C] { s.errors = []error{} return s } -// Check if the setting contains errors +// HasErrors checks if the setting contains errors func (s *Settings[C]) HasErrors() bool { return len(s.errors) > 0 } diff --git a/postprocessing-handler.go b/postprocessing-handler.go index 912750a64c4efb81861c23b8af05996c2c7a612f..92e72a8aabcb8f934adc2ccb86370a034d7190ea 100644 --- a/postprocessing-handler.go +++ b/postprocessing-handler.go @@ -22,13 +22,13 @@ func (s *Settings[C]) OnPostprocessing(hook PostprocessingHook) *Settings[C] { } // HasOnPostprocessingHook returns true if there are registered hooks. -func (s *Settings[C]) HasOnPostprocessingHook(hook PostprocessingHook) *Settings[C] { +func (s *Settings[C]) HasOnPostprocessingHook(hook PostprocessingHook) bool { for _, h := range s.hooks.postprocessing { if h == hook { - break + return true } } - return s + return false } // RemoveOnPostprocessingHook removes a change hook from the list of hooks.