From 368c77300d791a13fa1f31bce58eb4a62418b3f6 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 16 Apr 2024 08:23:17 -0700 Subject: [PATCH] [chore][internal/sqlquery] Make error public for future use (#32175) **Description:** This is part of https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/31915, to try to make it more manageable in size. This variable will be used by the SQL Server receiver. --- internal/sqlquery/db_client_test.go | 4 ++-- internal/sqlquery/row_scanner.go | 4 ++-- internal/sqlquery/scraper.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/sqlquery/db_client_test.go b/internal/sqlquery/db_client_test.go index 4546886b0ec0..9b149979a943 100644 --- a/internal/sqlquery/db_client_test.go +++ b/internal/sqlquery/db_client_test.go @@ -70,7 +70,7 @@ func TestDBSQLClient_Nulls(t *testing.T) { } rows, err := cl.QueryRows(context.Background()) assert.Error(t, err) - assert.True(t, errors.Is(err, errNullValueWarning)) + assert.True(t, errors.Is(err, ErrNullValueWarning)) assert.Len(t, rows, 1) assert.EqualValues(t, map[string]string{ "col_0": "42", @@ -96,7 +96,7 @@ func TestDBSQLClient_Nulls_MultiRow(t *testing.T) { assert.Len(t, uw, 2) for _, err := range uw { - assert.True(t, errors.Is(err, errNullValueWarning)) + assert.True(t, errors.Is(err, ErrNullValueWarning)) } } assert.Len(t, rows, 2) diff --git a/internal/sqlquery/row_scanner.go b/internal/sqlquery/row_scanner.go index 9ed0711dc97e..bfda8aab270e 100644 --- a/internal/sqlquery/row_scanner.go +++ b/internal/sqlquery/row_scanner.go @@ -12,7 +12,7 @@ import ( "go.uber.org/multierr" ) -var errNullValueWarning = errors.New("NULL value") +var ErrNullValueWarning = errors.New("NULL value") type rowScanner struct { cols map[string]func() (string, error) @@ -28,7 +28,7 @@ func newRowScanner(colTypes []colType) *rowScanner { var v any rs.cols[colName] = func() (string, error) { if v == nil { - return "", errNullValueWarning + return "", ErrNullValueWarning } format := "%v" if t, isTime := v.(time.Time); isTime { diff --git a/internal/sqlquery/scraper.go b/internal/sqlquery/scraper.go index 9db99d6ea198..31eafbef2161 100644 --- a/internal/sqlquery/scraper.go +++ b/internal/sqlquery/scraper.go @@ -71,7 +71,7 @@ func (s *Scraper) Scrape(ctx context.Context) (pmetric.Metrics, error) { out := pmetric.NewMetrics() rows, err := s.Client.QueryRows(ctx) if err != nil { - if errors.Is(err, errNullValueWarning) { + if errors.Is(err, ErrNullValueWarning) { s.Logger.Warn("problems encountered getting metric rows", zap.Error(err)) } else { return out, fmt.Errorf("Scraper: %w", err)