Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Feature/collect warnings #479

Merged
merged 1 commit into from
Oct 23, 2018
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
4 changes: 1 addition & 3 deletions sql/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"

opentracing "github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
"gopkg.in/src-d/go-errors.v1"
"gopkg.in/src-d/go-mysql-server.v0/sql"
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
Expand Down Expand Up @@ -58,8 +57,7 @@ func Parse(ctx *sql.Context, query string) (sql.Node, error) {
}

if s == "" {
logrus.WithField("query", query).
Infof("query became empty, so it will be ignored")
ctx.Warn(0, "query was empty after trimming comments, so it will be ignored")
return plan.Nothing, nil
}

Expand Down
2 changes: 2 additions & 0 deletions sql/plan/create_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ func (c *CreateIndex) createIndex(
},
})

ctx.Error(0, "unable to save the index: %s", err)
logrus.WithField("err", err).Error("unable to save the index")

deleted, err := c.Catalog.DeleteIndex(index.Database(), index.ID(), true)
if err != nil {
ctx.Error(0, "unable to delete index: %s", err)
logrus.WithField("err", err).Error("unable to delete the index")
} else {
<-deleted
Expand Down
5 changes: 2 additions & 3 deletions sql/plan/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plan
import (
"fmt"

"github.com/sirupsen/logrus"
errors "gopkg.in/src-d/go-errors.v1"
"gopkg.in/src-d/go-mysql-server.v0/sql"
)
Expand Down Expand Up @@ -60,12 +59,12 @@ func (t *LockTables) RowIter(ctx *sql.Context) (sql.RowIter, error) {
lockable, err := getLockable(l.Table)
if err != nil {
// If a table is not lockable, just skip it
logrus.Warn(err.Error())
ctx.Warn(0, err.Error())
continue
}

if err := lockable.Lock(ctx, l.Write); err != nil {
logrus.Error(err.Error())
ctx.Error(0, "unable to lock table: %s", err)
} else {
t.Catalog.LockTable(id, lockable.Name())
}
Expand Down
19 changes: 19 additions & 0 deletions sql/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sql

import (
"context"
"fmt"
"io"
"math"
"sync"
Expand Down Expand Up @@ -238,6 +239,24 @@ func (c *Context) WithContext(ctx context.Context) *Context {
return &Context{ctx, c.Session, c.Pid(), c.tracer}
}

// Error adds an error as warning to the session.
func (c *Context) Error(code int, msg string, args ...interface{}) {
c.Session.Warn(&Warning{
Level: "Error",
Code: code,
Message: fmt.Sprintf(msg, args...),
})
}

// Warn adds a warning to the session.
func (c *Context) Warn(code int, msg string, args ...interface{}) {
c.Session.Warn(&Warning{
Level: "Warning",
Code: code,
Message: fmt.Sprintf(msg, args...),
})
}

// NewSpanIter creates a RowIter executed in the given span.
func NewSpanIter(span opentracing.Span, iter RowIter) RowIter {
return &spanIter{
Expand Down