Skip to content

Commit

Permalink
Improve error message on unparsed json strings (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakozaur authored May 15, 2024
1 parent 03456a7 commit 6f206fa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions quesma/queryparser/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,16 @@ func (cw *ClickhouseQueryTranslator) parseQueryMap(queryMap QueryMap) SimpleQuer
logger.WarnWithCtxAndReason(cw.Ctx, logger.ReasonUnsupportedQuery(k)).Msgf("unsupported query type: %s, value: %v", k, v)
}
}
if len(queryMap) == 0 {
if len(queryMap) == 0 { // empty query is a valid query
return newSimpleQuery(NewSimpleStatement(""), true)
}
return newSimpleQuery(NewSimpleStatement("can't parse query: "+pp.Sprint(queryMap)), false)

// if we can't parse the query, we should show the bug
unparsedQuery := pp.Sprint(queryMap)
if prettyMarshal, err := json.Marshal(queryMap); err == nil {
unparsedQuery = string(prettyMarshal)
}
return newSimpleQuery(NewSimpleStatement("can't parse query: "+unparsedQuery), false)
}

// Parses each SimpleQuery separately, returns list of translated SQLs
Expand Down

0 comments on commit 6f206fa

Please sign in to comment.