@@ -13,32 +13,79 @@ func NewMultiGovHooks(hooks ...GovHooks) MultiGovHooks {
1313 return hooks
1414}
1515
16- func (h MultiGovHooks ) AfterProposalSubmission (ctx sdk.Context , proposalID uint64 ) {
16+ func (h MultiGovHooks ) AfterProposalSubmission (ctx sdk.Context , proposalID uint64 ) error {
17+ var errs error
1718 for i := range h {
18- h [i ].AfterProposalSubmission (ctx , proposalID )
19+ errs = JoinErrors ( errs , h [i ].AfterProposalSubmission (ctx , proposalID ) )
1920 }
21+ return errs
2022}
2123
22- func (h MultiGovHooks ) AfterProposalDeposit (ctx sdk.Context , proposalID uint64 , depositorAddr sdk.AccAddress ) {
24+ func (h MultiGovHooks ) AfterProposalDeposit (ctx sdk.Context , proposalID uint64 , depositorAddr sdk.AccAddress ) error {
25+ var errs error
2326 for i := range h {
24- h [i ].AfterProposalDeposit (ctx , proposalID , depositorAddr )
27+ errs = JoinErrors ( errs , h [i ].AfterProposalDeposit (ctx , proposalID , depositorAddr ) )
2528 }
29+ return errs
2630}
2731
28- func (h MultiGovHooks ) AfterProposalVote (ctx sdk.Context , proposalID uint64 , voterAddr sdk.AccAddress ) {
32+ func (h MultiGovHooks ) AfterProposalVote (ctx sdk.Context , proposalID uint64 , voterAddr sdk.AccAddress ) error {
33+ var errs error
2934 for i := range h {
30- h [i ].AfterProposalVote (ctx , proposalID , voterAddr )
35+ errs = JoinErrors ( errs , h [i ].AfterProposalVote (ctx , proposalID , voterAddr ) )
3136 }
37+ return errs
3238}
3339
34- func (h MultiGovHooks ) AfterProposalFailedMinDeposit (ctx sdk.Context , proposalID uint64 ) {
40+ func (h MultiGovHooks ) AfterProposalFailedMinDeposit (ctx sdk.Context , proposalID uint64 ) error {
41+ var errs error
3542 for i := range h {
36- h [i ].AfterProposalFailedMinDeposit (ctx , proposalID )
43+ errs = JoinErrors ( errs , h [i ].AfterProposalFailedMinDeposit (ctx , proposalID ) )
3744 }
45+ return errs
3846}
3947
40- func (h MultiGovHooks ) AfterProposalVotingPeriodEnded (ctx sdk.Context , proposalID uint64 ) {
48+ func (h MultiGovHooks ) AfterProposalVotingPeriodEnded (ctx sdk.Context , proposalID uint64 ) error {
49+ var errs error
4150 for i := range h {
42- h [i ].AfterProposalVotingPeriodEnded (ctx , proposalID )
51+ errs = JoinErrors ( errs , h [i ].AfterProposalVotingPeriodEnded (ctx , proposalID ) )
4352 }
53+ return errs
54+ }
55+
56+ // implementation of errors.Join() in Go 1.20, until we upgrade to that version
57+ func JoinErrors (errs ... error ) error {
58+ n := 0
59+ for _ , err := range errs {
60+ if err != nil {
61+ n ++
62+ }
63+ }
64+ if n == 0 {
65+ return nil
66+ }
67+ e := & joinError {
68+ errs : make ([]error , 0 , n ),
69+ }
70+ for _ , err := range errs {
71+ if err != nil {
72+ e .errs = append (e .errs , err )
73+ }
74+ }
75+ return e
76+ }
77+
78+ type joinError struct {
79+ errs []error
80+ }
81+
82+ func (e * joinError ) Error () string {
83+ var b []byte
84+ for i , err := range e .errs {
85+ if i > 0 {
86+ b = append (b , '\n' )
87+ }
88+ b = append (b , err .Error ()... )
89+ }
90+ return string (b )
4491}
0 commit comments