Skip to content

Commit

Permalink
gitbase: report repository id on errors
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <[email protected]>
  • Loading branch information
erizocosmico committed Jul 3, 2019
1 parent b2762b1 commit b323808
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 35 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Errors now report the repository causing the error, if possible.

## [0.22.0] - 2019-07-03

### Added
Expand All @@ -28,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed error iterating over non ready repositories ([src-d/go-borges#54](https://github.com/src-d/go-borges/pull/54))
- Error saying value could not be converted to bool.
- function: make array_length not fail with literal null ([#767](https://github.com/src-d/go-mysql-server/pull/767))
- server: kill queries on connection closed (([#769](https://github.com/src-d/go-mysql-server/pull/769)))
- server: kill queries on connection closed (([#769](https://github.com/src-d/go-mysql-server/pull/769)))

## [0.22.0-rc2] - 2019-06-24

Expand Down
4 changes: 2 additions & 2 deletions blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ func (r *blobsTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (blobsTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
6 changes: 3 additions & 3 deletions commit_blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"io"

"github.com/src-d/go-mysql-server/sql"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/src-d/go-mysql-server/sql"
)

type commitBlobsTable struct {
Expand Down Expand Up @@ -113,10 +113,10 @@ func (t *commitBlobsTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (commitBlobsTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
10 changes: 5 additions & 5 deletions commit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"io"

"github.com/sirupsen/logrus"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/src-d/go-mysql-server/sql/plan"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/expression"
"github.com/src-d/go-mysql-server/sql/plan"
)

type commitFilesTable struct {
Expand Down Expand Up @@ -125,10 +125,10 @@ func (t *commitFilesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (commitFilesTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
6 changes: 3 additions & 3 deletions commit_trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"gopkg.in/src-d/go-git.v4/plumbing"

"github.com/src-d/go-mysql-server/sql"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/src-d/go-mysql-server/sql"
)

type commitTreesTable struct {
Expand Down Expand Up @@ -106,10 +106,10 @@ func (t *commitTreesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

// IndexKeyValues implements the sql.IndexableTable interface.
Expand Down
4 changes: 2 additions & 2 deletions commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func (r *commitsTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (commitsTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
6 changes: 3 additions & 3 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"io"

"github.com/src-d/go-mysql-server/sql"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/filemode"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"github.com/src-d/go-mysql-server/sql"
)

type filesTable struct {
Expand Down Expand Up @@ -143,10 +143,10 @@ func (r *filesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (filesTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
2 changes: 1 addition & 1 deletion fs_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func setupErrorRepos(t *testing.T) (*sql.Context, CleanupFunc) {
tmpDir, err := ioutil.TempDir("", "gitbase")
require.NoError(err)

var rootFS billy.Filesystem = osfs.New(tmpDir)
rootFS := osfs.New(tmpDir)

lib, pool, err := newMultiPool()
require.NoError(err)
Expand Down
33 changes: 33 additions & 0 deletions partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,36 @@ func (i *partitionedIndexKeyValueIter) Close() error {
}
return nil
}

var errRepository = errors.NewKind("on repository %q")

func errorWithRepo(repo *Repository, err error) error {
return errRepository.Wrap(err, repo.ID())
}

type repoRowIter struct {
iter sql.RowIter
repo *Repository
}

func newRepoRowIter(repo *Repository, iter sql.RowIter) sql.RowIter {
return &repoRowIter{iter, repo}
}

func (i *repoRowIter) Next() (sql.Row, error) {
row, err := i.iter.Next()
if err != nil {
if err == io.EOF {
return nil, io.EOF
}
return nil, errorWithRepo(i.repo, err)
}
return row, nil
}

func (i *repoRowIter) Close() error {
if err := i.iter.Close(); err != nil {
return errorWithRepo(i.repo, err)
}
return nil
}
6 changes: 3 additions & 3 deletions ref_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"gopkg.in/src-d/go-git.v4/plumbing"

"github.com/src-d/go-mysql-server/sql"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"github.com/src-d/go-mysql-server/sql"
)

type refCommitsTable struct {
Expand Down Expand Up @@ -121,10 +121,10 @@ func (t *refCommitsTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (refCommitsTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
4 changes: 2 additions & 2 deletions references.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func (r *referencesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (referencesTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
6 changes: 3 additions & 3 deletions remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"io"

"github.com/src-d/go-mysql-server/sql"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/config"
"github.com/src-d/go-mysql-server/sql"
)

type remotesTable struct {
Expand Down Expand Up @@ -111,10 +111,10 @@ func (r *remotesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (remotesTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down
4 changes: 2 additions & 2 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func (r *repositoriesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (repositoriesTable) handledColumns() []string { return nil }
Expand Down
9 changes: 6 additions & 3 deletions squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ func (t *SquashedTable) PartitionRows(ctx *sql.Context, p sql.Partition) (sql.Ro
iter, err := t.iter.New(ctx, repo)
if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

if len(t.schemaMappings) == 0 {
return sql.NewSpanIter(
span,
NewChainableRowIter(iter),
newRepoRowIter(repo, NewChainableRowIter(iter)),
), nil
}

return sql.NewSpanIter(
span,
NewSchemaMapperIter(NewChainableRowIter(iter), t.schemaMappings),
newRepoRowIter(
repo,
NewSchemaMapperIter(NewChainableRowIter(iter), t.schemaMappings),
),
), nil
}

Expand Down
4 changes: 2 additions & 2 deletions tree_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func (r *treeEntriesTable) PartitionRows(

if err != nil {
span.Finish()
return nil, err
return nil, errorWithRepo(repo, err)
}

return sql.NewSpanIter(span, iter), nil
return sql.NewSpanIter(span, newRepoRowIter(repo, iter)), nil
}

func (treeEntriesTable) HandledFilters(filters []sql.Expression) []sql.Expression {
Expand Down

0 comments on commit b323808

Please sign in to comment.