all: use more go-ish error for constraint failures

This commit is contained in:
Ariel Mashraki
2019-12-17 22:55:33 +02:00
parent c6800a3869
commit 798d58f02b
78 changed files with 422 additions and 440 deletions

View File

@@ -235,7 +235,7 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
return 0, rollback(tx, err)
}
if int(affected) < len(nu.prev) {
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nu.prev))})
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nu.prev))})
}
}
}
@@ -266,7 +266,7 @@ func (nu *NodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
return 0, rollback(tx, err)
}
if int(affected) < len(nu.next) {
return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nu.next))})
return 0, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nu.next))})
}
}
}
@@ -495,7 +495,7 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
return nil, rollback(tx, err)
}
if int(affected) < len(nuo.prev) {
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nuo.prev))})
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"prev\" %v already connected to a different \"Node\"", keys(nuo.prev))})
}
}
}
@@ -526,7 +526,7 @@ func (nuo *NodeUpdateOne) sqlSave(ctx context.Context) (n *Node, err error) {
return nil, rollback(tx, err)
}
if int(affected) < len(nuo.next) {
return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nuo.next))})
return nil, rollback(tx, &ConstraintError{msg: fmt.Sprintf("one of \"next\" %v already connected to a different \"Node\"", keys(nuo.next))})
}
}
}