fix(platform): return empty history for missing tdengine tables
This commit is contained in:
@@ -514,6 +514,14 @@ func parseFloatString(value string) float64 {
|
|||||||
return parsed
|
return parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isTDengineTableNotExist(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
message := strings.ToLower(err.Error())
|
||||||
|
return strings.Contains(message, "table does not exist") || strings.Contains(message, "fail to get table info")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ProductionStore) HistoryLocations(ctx context.Context, query url.Values) (Page[HistoryLocationRow], error) {
|
func (s *ProductionStore) HistoryLocations(ctx context.Context, query url.Values) (Page[HistoryLocationRow], error) {
|
||||||
realtime, err := s.RealtimeLocations(ctx, query)
|
realtime, err := s.RealtimeLocations(ctx, query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -550,11 +558,17 @@ func (s *ProductionStore) HistoryLocationsFromTDengine(ctx context.Context, quer
|
|||||||
total := 0
|
total := 0
|
||||||
if built.CountText != "" {
|
if built.CountText != "" {
|
||||||
if err := s.tdengine.QueryRowContext(ctx, built.CountText, built.CountArgs...).Scan(&total); err != nil {
|
if err := s.tdengine.QueryRowContext(ctx, built.CountText, built.CountArgs...).Scan(&total); err != nil {
|
||||||
|
if isTDengineTableNotExist(err) {
|
||||||
|
return Page[HistoryLocationRow]{Items: []HistoryLocationRow{}, Total: 0, Limit: limit, Offset: offset}, nil
|
||||||
|
}
|
||||||
return Page[HistoryLocationRow]{}, err
|
return Page[HistoryLocationRow]{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rows, err := s.tdengine.QueryContext(ctx, built.Text, built.Args...)
|
rows, err := s.tdengine.QueryContext(ctx, built.Text, built.Args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if isTDengineTableNotExist(err) {
|
||||||
|
return Page[HistoryLocationRow]{Items: []HistoryLocationRow{}, Total: 0, Limit: limit, Offset: offset}, nil
|
||||||
|
}
|
||||||
return Page[HistoryLocationRow]{}, err
|
return Page[HistoryLocationRow]{}, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package platform
|
package platform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -24,6 +25,16 @@ func TestBuildVehicleServiceOverviewBatchSQLUsesFuzzyKeywordMatching(t *testing.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTDengineTableNotExistErrorIsRecognized(t *testing.T) {
|
||||||
|
err := errors.New("[0x2603] Fail to get table info, error: Table does not exist")
|
||||||
|
if !isTDengineTableNotExist(err) {
|
||||||
|
t.Fatalf("TDengine table-not-exist error should be recognized: %v", err)
|
||||||
|
}
|
||||||
|
if isTDengineTableNotExist(errors.New("connection refused")) {
|
||||||
|
t.Fatalf("unrelated errors should not be treated as empty table results")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVehicleServiceOverviewMatchesPartialKeyword(t *testing.T) {
|
func TestVehicleServiceOverviewMatchesPartialKeyword(t *testing.T) {
|
||||||
overview := VehicleServiceOverview{
|
overview := VehicleServiceOverview{
|
||||||
VIN: "LB9A32A24R0LS1426",
|
VIN: "LB9A32A24R0LS1426",
|
||||||
|
|||||||
Reference in New Issue
Block a user