Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: standardize behind error setting method #1129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions query_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (q *DeleteQuery) WhereAllWithDeleted() *DeleteQuery {

func (q *DeleteQuery) Order(orders ...string) *DeleteQuery {
if !q.hasFeature(feature.DeleteOrderLimit) {
q.err = feature.NewNotSupportError(feature.DeleteOrderLimit)
q.setErr(feature.NewNotSupportError(feature.DeleteOrderLimit))
return q
}
q.addOrder(orders...)
Expand All @@ -136,7 +136,7 @@ func (q *DeleteQuery) Order(orders ...string) *DeleteQuery {

func (q *DeleteQuery) OrderExpr(query string, args ...interface{}) *DeleteQuery {
if !q.hasFeature(feature.DeleteOrderLimit) {
q.err = feature.NewNotSupportError(feature.DeleteOrderLimit)
q.setErr(feature.NewNotSupportError(feature.DeleteOrderLimit))
return q
}
q.addOrderExpr(query, args...)
Expand All @@ -151,7 +151,7 @@ func (q *DeleteQuery) ForceDelete() *DeleteQuery {
// ------------------------------------------------------------------------------
func (q *DeleteQuery) Limit(n int) *DeleteQuery {
if !q.hasFeature(feature.DeleteOrderLimit) {
q.err = feature.NewNotSupportError(feature.DeleteOrderLimit)
q.setErr(feature.NewNotSupportError(feature.DeleteOrderLimit))
return q
}
q.setLimit(n)
Expand All @@ -165,7 +165,7 @@ func (q *DeleteQuery) Limit(n int) *DeleteQuery {
// To suppress the auto-generated RETURNING clause, use `Returning("NULL")`.
func (q *DeleteQuery) Returning(query string, args ...interface{}) *DeleteQuery {
if !q.hasFeature(feature.DeleteReturning) {
q.err = feature.NewNotSupportError(feature.DeleteOrderLimit)
q.setErr(feature.NewNotSupportError(feature.DeleteOrderLimit))
return q
}

Expand Down
2 changes: 1 addition & 1 deletion query_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (q *InsertQuery) ExcludeColumn(columns ...string) *InsertQuery {
// Value overwrites model value for the column.
func (q *InsertQuery) Value(column string, expr string, args ...interface{}) *InsertQuery {
if q.table == nil {
q.err = errNilModel
q.setErr(errNilModel)
return q
}
q.addValue(q.table, column, expr, args)
Expand Down
2 changes: 1 addition & 1 deletion query_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewMergeQuery(db *DB) *MergeQuery {
},
}
if q.db.dialect.Name() != dialect.MSSQL && q.db.dialect.Name() != dialect.PG {
q.err = errors.New("bun: merge not supported for current dialect")
q.setErr(errors.New("bun: merge not supported for current dialect"))
}
return q
}
Expand Down
2 changes: 1 addition & 1 deletion query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (q *SelectQuery) JoinOnOr(cond string, args ...interface{}) *SelectQuery {

func (q *SelectQuery) joinOn(cond string, args []interface{}, sep string) *SelectQuery {
if len(q.joins) == 0 {
q.err = errors.New("bun: query has no joins")
q.setErr(errors.New("bun: query has no joins"))
return q
}
j := &q.joins[len(q.joins)-1]
Expand Down
10 changes: 5 additions & 5 deletions query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (q *UpdateQuery) SetColumn(column string, query string, args ...interface{}
// Value overwrites model value for the column.
func (q *UpdateQuery) Value(column string, query string, args ...interface{}) *UpdateQuery {
if q.table == nil {
q.err = errNilModel
q.setErr(errNilModel)
return q
}
q.addValue(q.table, column, query, args)
Expand Down Expand Up @@ -154,7 +154,7 @@ func (q *UpdateQuery) JoinOnOr(cond string, args ...interface{}) *UpdateQuery {

func (q *UpdateQuery) joinOn(cond string, args []interface{}, sep string) *UpdateQuery {
if len(q.joins) == 0 {
q.err = errors.New("bun: query has no joins")
q.setErr(errors.New("bun: query has no joins"))
return q
}
j := &q.joins[len(q.joins)-1]
Expand Down Expand Up @@ -206,7 +206,7 @@ func (q *UpdateQuery) WhereAllWithDeleted() *UpdateQuery {
// ------------------------------------------------------------------------------
func (q *UpdateQuery) Order(orders ...string) *UpdateQuery {
if !q.hasFeature(feature.UpdateOrderLimit) {
q.err = feature.NewNotSupportError(feature.UpdateOrderLimit)
q.setErr(feature.NewNotSupportError(feature.UpdateOrderLimit))
return q
}
q.addOrder(orders...)
Expand All @@ -215,7 +215,7 @@ func (q *UpdateQuery) Order(orders ...string) *UpdateQuery {

func (q *UpdateQuery) OrderExpr(query string, args ...interface{}) *UpdateQuery {
if !q.hasFeature(feature.UpdateOrderLimit) {
q.err = feature.NewNotSupportError(feature.UpdateOrderLimit)
q.setErr(feature.NewNotSupportError(feature.UpdateOrderLimit))
return q
}
q.addOrderExpr(query, args...)
Expand All @@ -224,7 +224,7 @@ func (q *UpdateQuery) OrderExpr(query string, args ...interface{}) *UpdateQuery

func (q *UpdateQuery) Limit(n int) *UpdateQuery {
if !q.hasFeature(feature.UpdateOrderLimit) {
q.err = feature.NewNotSupportError(feature.UpdateOrderLimit)
q.setErr(feature.NewNotSupportError(feature.UpdateOrderLimit))
return q
}
q.setLimit(n)
Expand Down
2 changes: 1 addition & 1 deletion query_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (q *ValuesQuery) Column(columns ...string) *ValuesQuery {
// Value overwrites model value for the column.
func (q *ValuesQuery) Value(column string, expr string, args ...interface{}) *ValuesQuery {
if q.table == nil {
q.err = errNilModel
q.setErr(errNilModel)
return q
}
q.addValue(q.table, column, expr, args)
Expand Down
Loading