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

Commit 7f24997

Browse files
committed
sql: collect warnings and errors in the session
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
1 parent d7c9656 commit 7f24997

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

sql/parse/parse.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111

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

6059
if s == "" {
61-
logrus.WithField("query", query).
62-
Infof("query became empty, so it will be ignored")
60+
ctx.Warn(0, "query was empty after trimming comments, so it will be ignored")
6361
return plan.Nothing, nil
6462
}
6563

sql/plan/create_index.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ func (c *CreateIndex) createIndex(
201201
},
202202
})
203203

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

206207
deleted, err := c.Catalog.DeleteIndex(index.Database(), index.ID(), true)
207208
if err != nil {
209+
ctx.Error(0, "unable to delete index: %s", err)
208210
logrus.WithField("err", err).Error("unable to delete the index")
209211
} else {
210212
<-deleted

sql/plan/lock.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package plan
33
import (
44
"fmt"
55

6-
"github.com/sirupsen/logrus"
76
errors "gopkg.in/src-d/go-errors.v1"
87
"gopkg.in/src-d/go-mysql-server.v0/sql"
98
)
@@ -60,12 +59,12 @@ func (t *LockTables) RowIter(ctx *sql.Context) (sql.RowIter, error) {
6059
lockable, err := getLockable(l.Table)
6160
if err != nil {
6261
// If a table is not lockable, just skip it
63-
logrus.Warn(err.Error())
62+
ctx.Warn(0, err.Error())
6463
continue
6564
}
6665

6766
if err := lockable.Lock(ctx, l.Write); err != nil {
68-
logrus.Error(err.Error())
67+
ctx.Error(0, "unable to lock table: %s", err)
6968
} else {
7069
t.Catalog.LockTable(id, lockable.Name())
7170
}

sql/session.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sql
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"math"
78
"sync"
@@ -238,6 +239,24 @@ func (c *Context) WithContext(ctx context.Context) *Context {
238239
return &Context{ctx, c.Session, c.Pid(), c.tracer}
239240
}
240241

242+
// Error adds an error as warning to the session.
243+
func (c *Context) Error(code int, msg string, args ...interface{}) {
244+
c.Session.Warn(&Warning{
245+
Level: "Error",
246+
Code: code,
247+
Message: fmt.Sprintf(msg, args...),
248+
})
249+
}
250+
251+
// Warn adds a warning to the session.
252+
func (c *Context) Warn(code int, msg string, args ...interface{}) {
253+
c.Session.Warn(&Warning{
254+
Level: "Warning",
255+
Code: code,
256+
Message: fmt.Sprintf(msg, args...),
257+
})
258+
}
259+
241260
// NewSpanIter creates a RowIter executed in the given span.
242261
func NewSpanIter(span opentracing.Span, iter RowIter) RowIter {
243262
return &spanIter{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy