pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/bytebase/bytebase/commit/5fd7db10ea4bdbcade9a5d1d452df1faebb19565

b000615.css" /> fix(elasticsearch): handle parsing errors in GetQuerySpan (#19335) · bytebase/bytebase@5fd7db1 · GitHub
Skip to content

Commit 5fd7db1

Browse files
authored
fix(elasticsearch): handle parsing errors in GetQuerySpan (#19335)
Previously, GetQuerySpan ignored errors from ParseElasticsearchREST and returned QueryTypeUnknown for malformed queries (e.g. MongoDB queries). This resulted in a "permission denied" error ("disallowed query type") instead of a syntax error. This change modifies GetQuerySpan to: 1. Propagate errors from ParseElasticsearchREST. 2. Check for syntax errors in the ParseResult and return a formatted error if any exist. This ensures that invalid queries result in a proper syntax error message.
1 parent bb2a36c commit 5fd7db1

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

backend/plugin/parser/elasticsearch/query_span.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package elasticsearch
33
import (
44
"context"
55

6+
"github.com/pkg/errors"
7+
68
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
79
"github.com/bytebase/bytebase/backend/plugin/parser/base"
810
)
@@ -19,9 +21,21 @@ func GetQuerySpan(
1921
_, _ string,
2022
_ bool,
2123
) (*base.QuerySpan, error) {
22-
parseResult, _ := ParseElasticsearchREST(stmt.Text)
24+
parseResult, err := ParseElasticsearchREST(stmt.Text)
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
if parseResult == nil {
30+
return &base.QuerySpan{Type: base.QueryTypeUnknown}, nil
31+
}
32+
33+
if len(parseResult.Errors) > 0 {
34+
firstErr := parseResult.Errors[0]
35+
return nil, errors.Errorf("syntax error at line %d, column %d: %s", firstErr.Position.Line, firstErr.Position.Column, firstErr.Message)
36+
}
2337

24-
if parseResult == nil || len(parseResult.Requests) == 0 {
38+
if len(parseResult.Requests) == 0 {
2539
return &base.QuerySpan{Type: base.QueryTypeUnknown}, nil
2640
}
2741

backend/plugin/parser/elasticsearch/query_span_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ func TestGetQuerySpan(t *testing.T) {
5656
a.NoError(err)
5757
}
5858
}
59+
60+
func TestGetQuerySpan_Error(t *testing.T) {
61+
// MongoDB style query, definitely not ElasticSearch
62+
stmt := "db.users.find({})"
63+
span, err := GetQuerySpan(context.Background(), base.GetQuerySpanContext{}, base.Statement{Text: stmt}, "", "", false)
64+
65+
// New behavior: returns error
66+
require.Error(t, err)
67+
require.Nil(t, span)
68+
require.Contains(t, err.Error(), "Syntax error")
69+
}

backend/plugin/parser/elasticsearch/test-data/query_span.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,3 @@
189189
- description: PATCH document
190190
statement: "PATCH /my_index/_doc/1"
191191
queryType: 5 # DML
192-
193-
# Unknown method
194-
- description: Unknown method
195-
statement: "UNKNOWN /my_index"
196-
queryType: 0 # QueryTypeUnknown

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

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