Skip to content

Commit 9b4ef55

Browse files
authored
Merge pull request #692 from ydb-platform/issues-row-col
print issue row:col
2 parents 3d4624f + 0384e8a commit 9b4ef55

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

internal/xerrors/issues.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,24 @@ func (ii issues) String() string {
2626
b.WriteByte(',')
2727
}
2828
b.WriteByte('{')
29+
if p := m.GetPosition(); p != nil {
30+
if file := p.GetFile(); file != "" {
31+
b.WriteString(file)
32+
b.WriteByte(':')
33+
}
34+
b.WriteString(strconv.Itoa(int(p.GetRow())))
35+
b.WriteByte(':')
36+
b.WriteString(strconv.Itoa(int(p.GetColumn())))
37+
b.WriteString(" => ")
38+
}
2939
if code := m.GetIssueCode(); code != 0 {
3040
b.WriteByte('#')
3141
b.WriteString(strconv.Itoa(int(code)))
3242
b.WriteByte(' ')
3343
}
44+
b.WriteByte('\'')
3445
b.WriteString(strings.TrimSuffix(m.GetMessage(), "."))
46+
b.WriteByte('\'')
3547
if len(m.Issues) > 0 {
3648
b.WriteByte(' ')
3749
b.WriteString(issues(m.Issues).String())

internal/xerrors/operation_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func Test_operationError_Error(t *testing.T) {
5050
{
5151
Message: "issue one",
5252
IssueCode: 1,
53+
Position: &Ydb_Issue.IssueMessage_Position{
54+
Row: 15,
55+
Column: 3,
56+
File: "",
57+
},
5358
},
5459
{
5560
Message: "issue two",
@@ -58,6 +63,11 @@ func Test_operationError_Error(t *testing.T) {
5863
{
5964
Message: "issue three",
6065
IssueCode: 3,
66+
Position: &Ydb_Issue.IssueMessage_Position{
67+
Row: 16,
68+
Column: 4,
69+
File: "test.yql",
70+
},
6171
},
6272
{
6373
Message: "issue four",
@@ -66,7 +76,7 @@ func Test_operationError_Error(t *testing.T) {
6676
},
6777
},
6878
})),
69-
text: "operation/PRECONDITION_FAILED (code = 400120, issues = [{#1 issue one},{#2 issue two [{#3 issue three},{#4 issue four}]}])", //nolint:lll
79+
text: "operation/PRECONDITION_FAILED (code = 400120, issues = [{15:3 => #1 'issue one'},{#2 'issue two' [{test.yql:16:4 => #3 'issue three'},{#4 'issue four'}]}])", //nolint:lll
7080
},
7181
} {
7282
t.Run("", func(t *testing.T) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//go:build !fast
2+
// +build !fast
3+
4+
package integration
5+
6+
import (
7+
"context"
8+
"os"
9+
"path"
10+
"regexp"
11+
"testing"
12+
13+
"github.com/stretchr/testify/require"
14+
15+
"github.com/ydb-platform/ydb-go-sdk/v3"
16+
"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
17+
"github.com/ydb-platform/ydb-go-sdk/v3/table"
18+
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
19+
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
20+
)
21+
22+
func TestDataQueryIssueRowCol(t *testing.T) {
23+
ctx, cancel := context.WithCancel(context.Background())
24+
defer cancel()
25+
26+
db, err := ydb.Open(ctx,
27+
os.Getenv("YDB_CONNECTION_STRING"),
28+
ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")),
29+
)
30+
require.NoError(t, err)
31+
exists, err := sugar.IsTableExists(ctx, db.Scheme(), path.Join(db.Name(), "users"))
32+
require.NoError(t, err)
33+
if exists {
34+
err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
35+
return s.DropTable(ctx, path.Join(db.Name(), "users"))
36+
})
37+
require.NoError(t, err)
38+
}
39+
err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
40+
return s.CreateTable(ctx, path.Join(db.Name(), "users"),
41+
options.WithColumn("id", types.TypeUint64),
42+
options.WithPrimaryKeyColumn("id"),
43+
)
44+
})
45+
require.NoError(t, err)
46+
err = db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
47+
_, _, err = s.Execute(ctx, table.DefaultTxControl(), `
48+
UPSERT INTO "users" (id) VALUES (1);
49+
`, nil,
50+
)
51+
return err
52+
})
53+
require.Error(t, err)
54+
err = ydb.OperationError(err)
55+
require.Error(t, err)
56+
re := regexp.MustCompile(", address = [a-zA-Z0-9.:-]+,")
57+
errText := re.ReplaceAllStringFunc(err.Error(), func(s string) string {
58+
return ","
59+
})
60+
require.Equal(t, "operation/GENERIC_ERROR (code = 400080, issues = [{2:17 => 'String literal can not be used here'}])", errText) //nolint:lll
61+
}

0 commit comments

Comments
 (0)