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

Open
opened 6 months ago by 6543 · 0 comments
6543 commented 6 months ago

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` ... 6 months ago
lunny added the
kind/proposal
label 6 months ago
lunny added this to the 1.3.0 milestone 6 months ago
lunny added the
kind/proposal:accepted
label 6 months ago
lunny modified the milestone from 1.3.0 to 1.4.0 2 months ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.