From 6ce46f3011253bbe99f042482ec26b2d641883a8 Mon Sep 17 00:00:00 2001 From: lingniu Date: Sat, 4 Jul 2026 08:33:41 +0800 Subject: [PATCH] fix(platform): return empty history for missing tdengine tables --- .../apps/api/internal/platform/production_store.go | 14 ++++++++++++++ .../api/internal/platform/production_store_test.go | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/vehicle-data-platform/apps/api/internal/platform/production_store.go b/vehicle-data-platform/apps/api/internal/platform/production_store.go index 36587823..228f8925 100644 --- a/vehicle-data-platform/apps/api/internal/platform/production_store.go +++ b/vehicle-data-platform/apps/api/internal/platform/production_store.go @@ -514,6 +514,14 @@ func parseFloatString(value string) float64 { 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) { realtime, err := s.RealtimeLocations(ctx, query) if err != nil { @@ -550,11 +558,17 @@ func (s *ProductionStore) HistoryLocationsFromTDengine(ctx context.Context, quer total := 0 if built.CountText != "" { 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 } } rows, err := s.tdengine.QueryContext(ctx, built.Text, built.Args...) if err != nil { + if isTDengineTableNotExist(err) { + return Page[HistoryLocationRow]{Items: []HistoryLocationRow{}, Total: 0, Limit: limit, Offset: offset}, nil + } return Page[HistoryLocationRow]{}, err } defer rows.Close() diff --git a/vehicle-data-platform/apps/api/internal/platform/production_store_test.go b/vehicle-data-platform/apps/api/internal/platform/production_store_test.go index bd888023..f0af74ac 100644 --- a/vehicle-data-platform/apps/api/internal/platform/production_store_test.go +++ b/vehicle-data-platform/apps/api/internal/platform/production_store_test.go @@ -1,6 +1,7 @@ package platform import ( + "errors" "strings" "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) { overview := VehicleServiceOverview{ VIN: "LB9A32A24R0LS1426",