Backpropagate Errors on BeforeInsert, AfterInsert, BeforeUpdate, AfterUpdate ... #1924

Open
opened 2021-06-07 12:03:57 +00:00 by 6543 · 0 comments
Contributor

Struct functions: BeforeInsert, AfterInsert, BeforeUpdate, AfterUpdate, BeforeLoad and AfterLoad are executed but cant return an error.

It would be nice if they could return an error by the Insert who called them.

func (m *TestStruct) BeforeInsert(session *xorm.Session) error {
  return fmt.Error("test")
}

func test() {
  item := TestStruct{ID: 2, Value: "abc", Count: 2}
  err := xorm.Insert(&item)
  fmt.printf("%v", err)
}

return something like: BeforeInsert: test


https://github.com/go-gitea/gitea/pull/15157#discussion_r645997674

Struct functions: `BeforeInsert`, `AfterInsert`, `BeforeUpdate`, `AfterUpdate`, `BeforeLoad` and `AfterLoad` are executed but cant return an error. It would be nice if they could return an error by the Insert who called them. ```go func (m *TestStruct) BeforeInsert(session *xorm.Session) error { return fmt.Error("test") } func test() { item := TestStruct{ID: 2, Value: "abc", Count: 2} err := xorm.Insert(&item) fmt.printf("%v", err) } ``` return something like: `BeforeInsert: test` --- *https://github.com/go-gitea/gitea/pull/15157#discussion_r645997674*
6543 changed title from Backpropagate Errors on `BeforeInsert`, ` AfterInsert`, `BeforeUpdate`, `AfterUpdate` to Backpropagate Errors on `BeforeInsert`, ` AfterInsert`, `BeforeUpdate`, `AfterUpdate` ... 2021-06-07 12:04:29 +00:00
lunny added the
kind
proposal
label 2021-06-07 12:39:04 +00:00
lunny added this to the 1.3.0 milestone 2021-06-12 07:08:15 +00:00
lunny added the
proposal:accepted
label 2021-06-12 12:34:57 +00:00
lunny modified the milestone from 1.3.0 to 2.0.0 2021-10-20 00:55:48 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1924
No description provided.