Skip to content

Commit c316d75

Browse files
authored
return error frame during marco parsing errors (#37)
1 parent 42cb4ea commit c316d75

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

datasource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ func (ds *sqldatasource) handleQuery(ctx context.Context, req backend.DataQuery)
133133
// Convert the backend.DataQuery into a Query object
134134
q, err := GetQuery(req)
135135
if err != nil {
136-
return nil, err
136+
return getErrorFrameFromQuery(q), err
137137
}
138138

139139
// Apply supported macros to the query
140140
q.RawSQL, err = interpolate(ds.c, q)
141141
if err != nil {
142-
return nil, fmt.Errorf("%s: %w", "Could not apply macros", err)
142+
return getErrorFrameFromQuery(q), fmt.Errorf("%s: %w", "Could not apply macros", err)
143143
}
144144

145145
// Apply the default FillMode, overwritting it if the query specifies it
@@ -151,7 +151,7 @@ func (ds *sqldatasource) handleQuery(ctx context.Context, req backend.DataQuery)
151151
// Retrieve the database connection
152152
db, cacheKey, err := ds.getDB(q)
153153
if err != nil {
154-
return nil, err
154+
return getErrorFrameFromQuery(q), err
155155
}
156156

157157
if ds.driverSettings.Timeout != 0 {

macros.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func interpolate(driver Driver, query *Query) (string, error) {
3939
for key, macro := range macros {
4040
rgx, err := regexp.Compile(getMacroRegex(key))
4141
if err != nil {
42-
return "", err
42+
return rawSQL, err
4343
}
4444
matches := rgx.FindAllStringSubmatch(rawSQL, -1)
4545
for _, match := range matches {
@@ -56,7 +56,7 @@ func interpolate(driver Driver, query *Query) (string, error) {
5656

5757
res, err := macro(query.WithSQL(rawSQL), args)
5858
if err != nil {
59-
return "", err
59+
return rawSQL, err
6060
}
6161

6262
rawSQL = strings.Replace(rawSQL, match[0], res, -1)

0 commit comments

Comments
 (0)