From abca65ef26302887b417b38eea7915f77abeabfe Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Tue, 23 Jan 2024 01:11:41 +0530 Subject: [PATCH] refactor error group --- flow/connectors/bigquery/bigquery.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/flow/connectors/bigquery/bigquery.go b/flow/connectors/bigquery/bigquery.go index 58aa951261..e9f4fd114c 100644 --- a/flow/connectors/bigquery/bigquery.go +++ b/flow/connectors/bigquery/bigquery.go @@ -3,6 +3,7 @@ package connbigquery import ( "context" "encoding/json" + "errors" "fmt" "log/slog" "reflect" @@ -160,27 +161,25 @@ func TableCheck(ctx context.Context, client *bigquery.Client, dataset string) er }, }) if createErr != nil { - return fmt.Errorf("unable to validate table creation within dataset: %v. "+ + return fmt.Errorf("unable to validate table creation within dataset: %w. "+ "Please check if bigquery.tables.create permission has been granted", createErr) } - errors := []string{} + var errs []error insertQuery := client.Query(fmt.Sprintf("INSERT INTO %s.%s VALUES(true)", dataset, dummyTable)) _, insertErr := insertQuery.Run(ctx) if insertErr != nil { - errors = append(errors, fmt.Sprintf("unable to validate insertion into table: %v. ", insertErr)+ - "Please check if bigquery.jobs.create permission has been granted") + errs = append(errs, fmt.Errorf("unable to validate insertion into table: %w. ", insertErr)) } // Drop the table deleteErr := newTable.Delete(ctx) if deleteErr != nil { - errors = append(errors, fmt.Sprintf("unable to delete table :%v. ", deleteErr)+ - "Please check if bigquery.tables.delete permission has been granted") + errs = append(errs, fmt.Errorf("unable to delete table :%w. ", deleteErr)) } - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, ",")) + if len(errs) > 0 { + return errors.Join(errs...) } return nil