Skip to content

Commit 411843a

Browse files
authored
Fix error messages during ErrExit in all commands to be able to send the sanitized error to callhome (#2319)
1. Fixes the error msgs for callhome to not have any sensitive information. 2. Enables sending error msg to call home for every error exit
1 parent ceb675b commit 411843a

22 files changed

+107
-105
lines changed

yb-voyager/cmd/analyzeSchema.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func addSummaryDetailsForIndexes() {
302302
var indexesInfo []utils.IndexInfo
303303
found, err := metaDB.GetJsonObject(nil, metadb.SOURCE_INDEXES_INFO_KEY, &indexesInfo)
304304
if err != nil {
305-
utils.ErrExit("analyze schema report summary: load indexes info: %s", err)
305+
utils.ErrExit("failed to analyze schema while loading indexes info: %s", err)
306306
}
307307
if !found {
308308
return
@@ -1103,7 +1103,7 @@ func analyzeSchemaInternal(sourceDBConf *srcdb.Source, detectIssues bool) utils.
11031103
schemaAnalysisReport.Issues = lo.Filter(schemaAnalysisReport.Issues, func(i utils.AnalyzeSchemaIssue, index int) bool {
11041104
fixed, err := i.IsFixedIn(targetDbVersion)
11051105
if err != nil {
1106-
utils.ErrExit("checking if issue %v is supported: %v", i, err)
1106+
utils.ErrExit("error checking if analyze issue is supported: issue[%v]: %v", i, err)
11071107
}
11081108
return !fixed
11091109
})
@@ -1158,7 +1158,7 @@ func analyzeSchema() {
11581158

11591159
msr, err := metaDB.GetMigrationStatusRecord()
11601160
if err != nil {
1161-
utils.ErrExit("analyze schema : load migration status record: %s", err)
1161+
utils.ErrExit("failed to get the migration status record: %s", err)
11621162
}
11631163
analyzeSchemaInternal(msr.SourceDBConf, true)
11641164

@@ -1302,7 +1302,7 @@ var analyzeSchemaCmd = &cobra.Command{
13021302
validateReportOutputFormat(validOutputFormats, analyzeSchemaReportFormat)
13031303
err = validateAndSetTargetDbVersionFlag()
13041304
if err != nil {
1305-
utils.ErrExit("%v", err)
1305+
utils.ErrExit("failed to validate target db version: %v", err)
13061306
}
13071307
},
13081308

@@ -1331,7 +1331,7 @@ func validateReportOutputFormat(validOutputFormats []string, format string) {
13311331
return
13321332
}
13331333
}
1334-
utils.ErrExit("Error: Invalid output format: %s. Supported formats are %v", format, validOutputFormats)
1334+
utils.ErrExit("Error invalid report output format: %s. Supported formats are %v", format, validOutputFormats)
13351335
}
13361336

13371337
func schemaIsAnalyzed() bool {

yb-voyager/cmd/archiveChangesCommand.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
log "github.com/sirupsen/logrus"
2727
"github.com/spf13/cobra"
28+
2829
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
2930
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
3031
)
@@ -77,7 +78,7 @@ func archiveChangesCommandFn(cmd *cobra.Command, args []string) {
7778
defer wg.Done()
7879
err := copier.Run()
7980
if err != nil {
80-
utils.ErrExit("copying segments: %v", err)
81+
utils.ErrExit("failed to copy segments: %v", err)
8182
}
8283
}()
8384

@@ -86,7 +87,7 @@ func archiveChangesCommandFn(cmd *cobra.Command, args []string) {
8687
defer wg.Done()
8788
err := deleter.Run()
8889
if err != nil {
89-
utils.ErrExit("deleting segments: %v", err)
90+
utils.ErrExit("failed to delete segments: %v", err)
9091
}
9192
}()
9293

@@ -133,7 +134,7 @@ func (d *EventSegmentDeleter) isFSUtilisationExceeded() bool {
133134
}
134135
fsUtilization, err := utils.GetFSUtilizationPercentage(exportDir)
135136
if err != nil {
136-
utils.ErrExit("get fs utilization: %v", err)
137+
utils.ErrExit("failed to get fs utilization: %v", err)
137138
}
138139

139140
return fsUtilization > d.FSUtilisationThreshold

yb-voyager/cmd/assessMigrationBulkCommand.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var assessMigrationBulkCmd = &cobra.Command{
6161
Run: func(cmd *cobra.Command, args []string) {
6262
err := assessMigrationBulk()
6363
if err != nil {
64-
utils.ErrExit("failed assess migration bulk: %s", err)
64+
utils.ErrExit("%s", err)
6565
}
6666
packAndSendAssessMigrationBulkPayload(COMPLETE, "")
6767
},
@@ -142,22 +142,22 @@ func assessMigrationBulk() error {
142142
// cleaning all export-dir present inside bulk-assessment-dir
143143
matches, err := filepath.Glob(fmt.Sprintf("%s/*-export-dir", bulkAssessmentDir))
144144
if err != nil {
145-
return fmt.Errorf("error while cleaning up export directories: %w", err)
145+
return fmt.Errorf("error while cleaning up export directories for bulk assessment in case of start-clean: %w", err)
146146
}
147147
for _, match := range matches {
148148
utils.CleanDir(match)
149149
}
150150

151151
err = os.RemoveAll(filepath.Join(bulkAssessmentDir, fmt.Sprintf("%s%s", BULK_ASSESSMENT_FILE_NAME, HTML_EXTENSION)))
152152
if err != nil {
153-
return fmt.Errorf("failed to remove bulk assessment report: %w", err)
153+
return fmt.Errorf("failed to remove bulk assessment report in case of start-clean: %w", err)
154154
}
155155
}
156156

157157
var err error
158158
bulkAssessmentDBConfigs, err = parseFleetConfigFile(fleetConfigPath)
159159
if err != nil {
160-
return fmt.Errorf("failed to parse fleet config file: %w", err)
160+
return fmt.Errorf("failed to parse fleet config file for bulk assessment: %w", err)
161161
}
162162

163163
for _, dbConfig := range bulkAssessmentDBConfigs {
@@ -454,7 +454,7 @@ func isMigrationAssessmentDoneForConfig(dbConfig AssessMigrationDBConfig) bool {
454454

455455
func validateBulkAssessmentDirFlag() {
456456
if bulkAssessmentDir == "" {
457-
utils.ErrExit(`ERROR: required flag "bulk-assessment-dir" not set`)
457+
utils.ErrExit(`ERROR required flag "bulk-assessment-dir" not set`)
458458
}
459459
if !utils.FileOrFolderExists(bulkAssessmentDir) {
460460
utils.ErrExit("bulk-assessment-dir doesn't exists: %q\n", bulkAssessmentDir)
@@ -479,7 +479,7 @@ var fleetConfDbIdentifierFields = []string{SOURCE_DB_NAME, ORACLE_DB_SID, ORACLE
479479

480480
func validateFleetConfigFile(filePath string) error {
481481
if filePath == "" {
482-
utils.ErrExit(`ERROR: required flag "fleet-config-file" not set`)
482+
utils.ErrExit(`ERROR required flag "fleet-config-file" not set`)
483483
}
484484
// Check if the file exists
485485
if !utils.FileOrFolderExists(filePath) {

yb-voyager/cmd/assessMigrationCommand.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var assessMigrationCmd = &cobra.Command{
9393
validateOracleParams()
9494
err = validateAndSetTargetDbVersionFlag()
9595
if err != nil {
96-
utils.ErrExit("%v", err)
96+
utils.ErrExit("failed to validate target db version: %v", err)
9797
}
9898
if cmd.Flags().Changed("assessment-metadata-dir") {
9999
validateAssessmentMetadataDirFlag()
@@ -113,8 +113,7 @@ var assessMigrationCmd = &cobra.Command{
113113
Run: func(cmd *cobra.Command, args []string) {
114114
err := assessMigration()
115115
if err != nil {
116-
packAndSendAssessMigrationPayload(ERROR, err.Error())
117-
utils.ErrExit("failed to assess migration: %s", err)
116+
utils.ErrExit("%s", err)
118117
}
119118
packAndSendAssessMigrationPayload(COMPLETE, "")
120119
},
@@ -314,14 +313,14 @@ func assessMigration() (err error) {
314313
if source.Password == "" {
315314
source.Password, err = askPassword("source DB", source.User, "SOURCE_DB_PASSWORD")
316315
if err != nil {
317-
return fmt.Errorf("failed to get source DB password: %w", err)
316+
return fmt.Errorf("failed to get source DB password for assessing migration: %w", err)
318317
}
319318
}
320319

321320
if assessmentMetadataDirFlag == "" { // only in case of source connectivity
322321
err := source.DB().Connect()
323322
if err != nil {
324-
utils.ErrExit("error connecting source db: %v", err)
323+
return fmt.Errorf("failed to connect source db for assessing migration: %v", err)
325324
}
326325

327326
// We will require source db connection for the below checks
@@ -331,7 +330,7 @@ func assessMigration() (err error) {
331330
log.Info("checking source DB version")
332331
err = source.DB().CheckSourceDBVersion(exportType)
333332
if err != nil {
334-
return fmt.Errorf("source DB version check failed: %w", err)
333+
return fmt.Errorf("failed to check source DB version for assess migration: %w", err)
335334
}
336335

337336
// Check if required binaries are installed.
@@ -345,7 +344,7 @@ func assessMigration() (err error) {
345344

346345
res := source.DB().CheckSchemaExists()
347346
if !res {
348-
return fmt.Errorf("schema %q does not exist", source.Schema)
347+
return fmt.Errorf("failed to check if source schema exist: %q", source.Schema)
349348
}
350349

351350
// Check if source db has permissions to assess migration
@@ -588,7 +587,7 @@ func checkStartCleanForAssessMigration(metadataDirPassedByUser bool) {
588587
utils.CleanDir(filepath.Join(assessmentDir, "dbs"))
589588
err := ClearMigrationAssessmentDone()
590589
if err != nil {
591-
utils.ErrExit("failed to start clean: %v", err)
590+
utils.ErrExit("failed to clear migration assessment completed flag in msr during start clean: %v", err)
592591
}
593592
} else {
594593
utils.ErrExit("assessment metadata or reports files already exist in the assessment directory: '%s'. Use the --start-clean flag to clear the directory before proceeding.", assessmentDir)
@@ -942,7 +941,7 @@ func getUnsupportedFeaturesFromSchemaAnalysisReport(featureName string, issueDes
942941
minVersionsFixedInSet = true
943942
}
944943
if !areMinVersionsFixedInEqual(minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn) {
945-
utils.ErrExit("Issues belonging to UnsupportedFeature %s have different minimum versions fixed in: %v, %v", featureName, minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn)
944+
utils.ErrExit("Issues belonging to UnsupportedFeature %s have different minimum versions fixed in: %v, %v", analyzeIssue.Name, minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn)
946945
}
947946

948947
objectInfo := ObjectInfo{
@@ -1697,20 +1696,20 @@ func getSupportedVersionString(minimumVersionsFixedIn map[string]*ybversion.YBVe
16971696

16981697
func validateSourceDBTypeForAssessMigration() {
16991698
if source.DBType == "" {
1700-
utils.ErrExit("Error: required flag \"source-db-type\" not set")
1699+
utils.ErrExit("Error required flag \"source-db-type\" not set")
17011700
}
17021701

17031702
source.DBType = strings.ToLower(source.DBType)
17041703
if !slices.Contains(assessMigrationSupportedDBTypes, source.DBType) {
1705-
utils.ErrExit("Error: Invalid source-db-type: %q. Supported source db types for assess-migration are: [%v]",
1704+
utils.ErrExit("Error Invalid source-db-type: %q. Supported source db types for assess-migration are: [%v]",
17061705
source.DBType, strings.Join(assessMigrationSupportedDBTypes, ", "))
17071706
}
17081707
}
17091708

17101709
func validateAssessmentMetadataDirFlag() {
17111710
if assessmentMetadataDirFlag != "" {
17121711
if !utils.FileOrFolderExists(assessmentMetadataDirFlag) {
1713-
utils.ErrExit("assessment metadata directory: %q provided with `--assessment-metadata-dir` flag does not exist", assessmentMetadataDirFlag)
1712+
utils.ErrExit("provided with `--assessment-metadata-dir` flag does not exist: %q ", assessmentMetadataDirFlag)
17141713
} else {
17151714
log.Infof("using provided assessment metadata directory: %s", assessmentMetadataDirFlag)
17161715
}

yb-voyager/cmd/common.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
_ "github.com/godror/godror"
3838
"github.com/google/uuid"
3939
"github.com/gosuri/uitable"
40+
"github.com/hashicorp/go-version"
4041
_ "github.com/mattn/go-sqlite3"
4142
"github.com/mitchellh/go-ps"
4243
"github.com/samber/lo"
@@ -45,7 +46,6 @@ import (
4546
"golang.org/x/exp/slices"
4647
"golang.org/x/term"
4748

48-
"github.com/hashicorp/go-version"
4949
"github.com/yugabyte/yb-voyager/yb-voyager/src/callhome"
5050
"github.com/yugabyte/yb-voyager/yb-voyager/src/cp"
5151
"github.com/yugabyte/yb-voyager/yb-voyager/src/datafile"
@@ -141,7 +141,7 @@ func getMappingForTableNameVsTableFileName(dataDirPath string, noWait bool) map[
141141
log.Infof("cmd: %s", pgRestoreCmd.String())
142142
log.Infof("output: %s", string(stdOut))
143143
if err != nil {
144-
utils.ErrExit("ERROR: couldn't parse the TOC file to collect the tablenames for data files: %v", err)
144+
utils.ErrExit("couldn't parse the TOC file to collect the tablenames for data files: %v", err)
145145
}
146146

147147
tableNameVsFileNameMap := make(map[string]string)
@@ -755,7 +755,7 @@ func GetSourceDBTypeFromMSR() string {
755755

756756
func validateMetaDBCreated() {
757757
if !metaDBIsCreated(exportDir) {
758-
utils.ErrExit("ERROR: no metadb found in export-dir")
758+
utils.ErrExit("ERROR no metadb found in export-dir")
759759
}
760760
}
761761

yb-voyager/cmd/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func GetCategoryDescription(category string) string {
259259
case MIGRATION_CAVEATS_CATEGORY: // or constants.MIGRATION_CAVEATS (identical)
260260
return MIGRATION_CAVEATS_CATEGORY_DESCRIPTION
261261
default:
262-
utils.ErrExit("ERROR: unsupported assessment issue category %q", category)
262+
utils.ErrExit("ERROR unsupported assessment issue category %q", category)
263263
}
264264
return ""
265265
}

yb-voyager/cmd/cutover.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020

2121
"github.com/spf13/cobra"
22+
2223
"github.com/yugabyte/yb-voyager/yb-voyager/src/dbzm"
2324
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
2425
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
@@ -136,7 +137,7 @@ func ExitIfAlreadyCutover(importerOrExporterRole string) {
136137

137138
record, err := metaDB.GetMigrationStatusRecord()
138139
if err != nil {
139-
utils.ErrExit("exit if already cutover: load migration status record: %s", err)
140+
utils.ErrExit("error getting migration status record to check cutover: %s", err)
140141
}
141142
cTAlreadyCompleted := "cutover already completed for this migration, aborting..."
142143
cSRAlreadyCompleted := "cutover to source-replica already completed for this migration, aborting..."

yb-voyager/cmd/cutoverStatus.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/fatih/color"
2222
"github.com/spf13/cobra"
23+
2324
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
2425
)
2526

@@ -58,7 +59,7 @@ func checkAndReportCutoverStatus() {
5859

5960
msr, err := metaDB.GetMigrationStatusRecord()
6061
if err != nil {
61-
utils.ErrExit("analyze schema report summary: load migration status record: %s", err)
62+
utils.ErrExit("error getting migration status record: %s", err)
6263
}
6364
if msr.FallbackEnabled {
6465
reportCutoverToSourceStatus()

yb-voyager/cmd/endMigrationCommand.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var endMigrationCmd = &cobra.Command{
5353
}
5454
err = validateEndMigrationFlags(cmd)
5555
if err != nil {
56-
utils.ErrExit(err.Error())
56+
utils.ErrExit("failed to validate end-migration flags: %v", err.Error())
5757
}
5858

5959
},

yb-voyager/cmd/export.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,21 @@ func registerExportDataFlags(cmd *cobra.Command) {
252252

253253
func validateSourceDBType() {
254254
if source.DBType == "" {
255-
utils.ErrExit("Error: required flag \"source-db-type\" not set")
255+
utils.ErrExit("Error required flag \"source-db-type\" not set")
256256
}
257257

258258
source.DBType = strings.ToLower(source.DBType)
259259
if !slices.Contains(supportedSourceDBTypes, source.DBType) {
260-
utils.ErrExit("Error: Invalid source-db-type: %q. Supported source db types are: (postgresql, oracle, mysql)", source.DBType)
260+
utils.ErrExit("Error Invalid source-db-type: %q. Supported source db types are: (postgresql, oracle, mysql)", source.DBType)
261261
}
262262
}
263263

264264
func validateConflictsBetweenTableListFlags(tableList string, excludeTableList string) {
265265
if tableList != "" && tableListFilePath != "" {
266-
utils.ErrExit("Error: Only one of --table-list and --table-list-file-path are allowed")
266+
utils.ErrExit("Error Only one of --table-list and --table-list-file-path are allowed")
267267
}
268268
if excludeTableList != "" && excludeTableListFilePath != "" {
269-
utils.ErrExit("Error: Only one of --exclude-table-list and --exclude-table-list-file-path are allowed")
269+
utils.ErrExit("Error Only one of --exclude-table-list and --exclude-table-list-file-path are allowed")
270270
}
271271
}
272272

@@ -278,10 +278,10 @@ func validateSourceSchema() {
278278
schemaList := utils.CsvStringToSlice(source.Schema)
279279
switch source.DBType {
280280
case MYSQL:
281-
utils.ErrExit("Error: --source-db-schema flag is not valid for 'MySQL' db type")
281+
utils.ErrExit("Error --source-db-schema flag is not valid for 'MySQL' db type")
282282
case ORACLE:
283283
if len(schemaList) > 1 {
284-
utils.ErrExit("Error: single schema at a time is allowed to export from oracle. List of schemas provided: %s", schemaList)
284+
utils.ErrExit("Error single schema at a time is allowed to export from oracle. List of schemas provided: %s", schemaList)
285285
}
286286
case POSTGRESQL:
287287
// In PG, its supported to export more than one schema
@@ -291,7 +291,7 @@ func validateSourceSchema() {
291291

292292
func validatePortRange() {
293293
if source.Port < 0 || source.Port > 65535 {
294-
utils.ErrExit("Error: Invalid port number %d. Valid range is 0-65535", source.Port)
294+
utils.ErrExit("Error Invalid port number %d. Valid range is 0-65535", source.Port)
295295
}
296296
}
297297

@@ -313,7 +313,7 @@ func validateOracleParams() {
313313
source.Schema = strings.ToUpper(source.Schema)
314314
}
315315
if source.DBName == "" && source.DBSid == "" && source.TNSAlias == "" {
316-
utils.ErrExit(`Error: one flag required out of "oracle-tns-alias", "source-db-name", "oracle-db-sid" required.`)
316+
utils.ErrExit(`Error one flag required out of "oracle-tns-alias", "source-db-name", "oracle-db-sid" required.`)
317317
} else if source.TNSAlias != "" {
318318
//Priority order for Oracle: oracle-tns-alias > source-db-name > oracle-db-sid
319319
// TODO: revisit voyager code wrt the priority among: sid, tnsalias, dbname
@@ -340,7 +340,7 @@ func validateOracleParams() {
340340
utils.PrintAndLog("Using CDB SID for export.")
341341
}
342342
if source.DBName == "" {
343-
utils.ErrExit(`Error: When using Container DB setup, specifying PDB via oracle-tns-alias or oracle-db-sid is not allowed. Please specify PDB name via source-db-name`)
343+
utils.ErrExit(`Error when using Container DB setup, specifying PDB via oracle-tns-alias or oracle-db-sid is not allowed. Please specify PDB name via source-db-name`)
344344
}
345345
}
346346

@@ -378,7 +378,7 @@ func markFlagsRequired(cmd *cobra.Command) {
378378
func validateExportTypeFlag() {
379379
exportType = strings.ToLower(exportType)
380380
if !slices.Contains(validExportTypes, exportType) {
381-
utils.ErrExit("Error: Invalid export-type: %q. Supported export types are: %s", exportType, validExportTypes)
381+
utils.ErrExit("Error Invalid export-type: %q. Supported export types are: %s", exportType, validExportTypes)
382382
}
383383
}
384384

0 commit comments

Comments
 (0)