Skip to content

Commit

Permalink
sql/internal/sqlx: add WrapIndentErr helper to builder (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m authored May 21, 2024
1 parent 6ad6ea3 commit 6d0b2db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sql/internal/sqlx/sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ func (b *Builder) WrapIndent(f func(b *Builder)) *Builder {
})
}

// WrapIndentErr is like WrapErr but with extra level of indentation.
func (b *Builder) WrapIndentErr(f func(b *Builder) error) error {
var err error
b.Wrap(func(b *Builder) {
b.IndentIn()
err = f(b)
b.IndentOut()
b.NL()
})
return err
}

// Clone returns a duplicate of the builder.
func (b *Builder) Clone() *Builder {
return &Builder{
Expand Down
1 change: 1 addition & 0 deletions sql/internal/sqlx/sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestBuilder(t *testing.T) {

// WrapErr.
require.EqualError(t, b.WrapErr(func(*Builder) error { return errors.New("oops") }), "oops")
require.EqualError(t, b.WrapIndentErr(func(*Builder) error { return errors.New("oops") }), "oops")
}

func TestBuilder_Qualifier(t *testing.T) {
Expand Down

0 comments on commit 6d0b2db

Please sign in to comment.