Skip to content

Commit

Permalink
Fix error messages during ErrExit in all commands to be able to send …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
priyanshi-yb authored Feb 20, 2025
1 parent ceb675b commit 411843a
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 105 deletions.
10 changes: 5 additions & 5 deletions yb-voyager/cmd/analyzeSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func addSummaryDetailsForIndexes() {
var indexesInfo []utils.IndexInfo
found, err := metaDB.GetJsonObject(nil, metadb.SOURCE_INDEXES_INFO_KEY, &indexesInfo)
if err != nil {
utils.ErrExit("analyze schema report summary: load indexes info: %s", err)
utils.ErrExit("failed to analyze schema while loading indexes info: %s", err)
}
if !found {
return
Expand Down Expand Up @@ -1103,7 +1103,7 @@ func analyzeSchemaInternal(sourceDBConf *srcdb.Source, detectIssues bool) utils.
schemaAnalysisReport.Issues = lo.Filter(schemaAnalysisReport.Issues, func(i utils.AnalyzeSchemaIssue, index int) bool {
fixed, err := i.IsFixedIn(targetDbVersion)
if err != nil {
utils.ErrExit("checking if issue %v is supported: %v", i, err)
utils.ErrExit("error checking if analyze issue is supported: issue[%v]: %v", i, err)
}
return !fixed
})
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func analyzeSchema() {

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

Expand Down Expand Up @@ -1302,7 +1302,7 @@ var analyzeSchemaCmd = &cobra.Command{
validateReportOutputFormat(validOutputFormats, analyzeSchemaReportFormat)
err = validateAndSetTargetDbVersionFlag()
if err != nil {
utils.ErrExit("%v", err)
utils.ErrExit("failed to validate target db version: %v", err)
}
},

Expand Down Expand Up @@ -1331,7 +1331,7 @@ func validateReportOutputFormat(validOutputFormats []string, format string) {
return
}
}
utils.ErrExit("Error: Invalid output format: %s. Supported formats are %v", format, validOutputFormats)
utils.ErrExit("Error invalid report output format: %s. Supported formats are %v", format, validOutputFormats)
}

func schemaIsAnalyzed() bool {
Expand Down
7 changes: 4 additions & 3 deletions yb-voyager/cmd/archiveChangesCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
)
Expand Down Expand Up @@ -77,7 +78,7 @@ func archiveChangesCommandFn(cmd *cobra.Command, args []string) {
defer wg.Done()
err := copier.Run()
if err != nil {
utils.ErrExit("copying segments: %v", err)
utils.ErrExit("failed to copy segments: %v", err)
}
}()

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

Expand Down Expand Up @@ -133,7 +134,7 @@ func (d *EventSegmentDeleter) isFSUtilisationExceeded() bool {
}
fsUtilization, err := utils.GetFSUtilizationPercentage(exportDir)
if err != nil {
utils.ErrExit("get fs utilization: %v", err)
utils.ErrExit("failed to get fs utilization: %v", err)
}

return fsUtilization > d.FSUtilisationThreshold
Expand Down
12 changes: 6 additions & 6 deletions yb-voyager/cmd/assessMigrationBulkCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var assessMigrationBulkCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := assessMigrationBulk()
if err != nil {
utils.ErrExit("failed assess migration bulk: %s", err)
utils.ErrExit("%s", err)
}
packAndSendAssessMigrationBulkPayload(COMPLETE, "")
},
Expand Down Expand Up @@ -142,22 +142,22 @@ func assessMigrationBulk() error {
// cleaning all export-dir present inside bulk-assessment-dir
matches, err := filepath.Glob(fmt.Sprintf("%s/*-export-dir", bulkAssessmentDir))
if err != nil {
return fmt.Errorf("error while cleaning up export directories: %w", err)
return fmt.Errorf("error while cleaning up export directories for bulk assessment in case of start-clean: %w", err)
}
for _, match := range matches {
utils.CleanDir(match)
}

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

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

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

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

func validateFleetConfigFile(filePath string) error {
if filePath == "" {
utils.ErrExit(`ERROR: required flag "fleet-config-file" not set`)
utils.ErrExit(`ERROR required flag "fleet-config-file" not set`)
}
// Check if the file exists
if !utils.FileOrFolderExists(filePath) {
Expand Down
23 changes: 11 additions & 12 deletions yb-voyager/cmd/assessMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var assessMigrationCmd = &cobra.Command{
validateOracleParams()
err = validateAndSetTargetDbVersionFlag()
if err != nil {
utils.ErrExit("%v", err)
utils.ErrExit("failed to validate target db version: %v", err)
}
if cmd.Flags().Changed("assessment-metadata-dir") {
validateAssessmentMetadataDirFlag()
Expand All @@ -113,8 +113,7 @@ var assessMigrationCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := assessMigration()
if err != nil {
packAndSendAssessMigrationPayload(ERROR, err.Error())
utils.ErrExit("failed to assess migration: %s", err)
utils.ErrExit("%s", err)
}
packAndSendAssessMigrationPayload(COMPLETE, "")
},
Expand Down Expand Up @@ -314,14 +313,14 @@ func assessMigration() (err error) {
if source.Password == "" {
source.Password, err = askPassword("source DB", source.User, "SOURCE_DB_PASSWORD")
if err != nil {
return fmt.Errorf("failed to get source DB password: %w", err)
return fmt.Errorf("failed to get source DB password for assessing migration: %w", err)
}
}

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

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

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

res := source.DB().CheckSchemaExists()
if !res {
return fmt.Errorf("schema %q does not exist", source.Schema)
return fmt.Errorf("failed to check if source schema exist: %q", source.Schema)
}

// Check if source db has permissions to assess migration
Expand Down Expand Up @@ -588,7 +587,7 @@ func checkStartCleanForAssessMigration(metadataDirPassedByUser bool) {
utils.CleanDir(filepath.Join(assessmentDir, "dbs"))
err := ClearMigrationAssessmentDone()
if err != nil {
utils.ErrExit("failed to start clean: %v", err)
utils.ErrExit("failed to clear migration assessment completed flag in msr during start clean: %v", err)
}
} else {
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)
Expand Down Expand Up @@ -942,7 +941,7 @@ func getUnsupportedFeaturesFromSchemaAnalysisReport(featureName string, issueDes
minVersionsFixedInSet = true
}
if !areMinVersionsFixedInEqual(minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn) {
utils.ErrExit("Issues belonging to UnsupportedFeature %s have different minimum versions fixed in: %v, %v", featureName, minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn)
utils.ErrExit("Issues belonging to UnsupportedFeature %s have different minimum versions fixed in: %v, %v", analyzeIssue.Name, minVersionsFixedIn, analyzeIssue.MinimumVersionsFixedIn)
}

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

func validateSourceDBTypeForAssessMigration() {
if source.DBType == "" {
utils.ErrExit("Error: required flag \"source-db-type\" not set")
utils.ErrExit("Error required flag \"source-db-type\" not set")
}

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

func validateAssessmentMetadataDirFlag() {
if assessmentMetadataDirFlag != "" {
if !utils.FileOrFolderExists(assessmentMetadataDirFlag) {
utils.ErrExit("assessment metadata directory: %q provided with `--assessment-metadata-dir` flag does not exist", assessmentMetadataDirFlag)
utils.ErrExit("provided with `--assessment-metadata-dir` flag does not exist: %q ", assessmentMetadataDirFlag)
} else {
log.Infof("using provided assessment metadata directory: %s", assessmentMetadataDirFlag)
}
Expand Down
6 changes: 3 additions & 3 deletions yb-voyager/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
_ "github.com/godror/godror"
"github.com/google/uuid"
"github.com/gosuri/uitable"
"github.com/hashicorp/go-version"
_ "github.com/mattn/go-sqlite3"
"github.com/mitchellh/go-ps"
"github.com/samber/lo"
Expand All @@ -45,7 +46,6 @@ import (
"golang.org/x/exp/slices"
"golang.org/x/term"

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

tableNameVsFileNameMap := make(map[string]string)
Expand Down Expand Up @@ -755,7 +755,7 @@ func GetSourceDBTypeFromMSR() string {

func validateMetaDBCreated() {
if !metaDBIsCreated(exportDir) {
utils.ErrExit("ERROR: no metadb found in export-dir")
utils.ErrExit("ERROR no metadb found in export-dir")
}
}

Expand Down
2 changes: 1 addition & 1 deletion yb-voyager/cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func GetCategoryDescription(category string) string {
case MIGRATION_CAVEATS_CATEGORY: // or constants.MIGRATION_CAVEATS (identical)
return MIGRATION_CAVEATS_CATEGORY_DESCRIPTION
default:
utils.ErrExit("ERROR: unsupported assessment issue category %q", category)
utils.ErrExit("ERROR unsupported assessment issue category %q", category)
}
return ""
}
3 changes: 2 additions & 1 deletion yb-voyager/cmd/cutover.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/spf13/cobra"

"github.com/yugabyte/yb-voyager/yb-voyager/src/dbzm"
"github.com/yugabyte/yb-voyager/yb-voyager/src/metadb"
"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
Expand Down Expand Up @@ -136,7 +137,7 @@ func ExitIfAlreadyCutover(importerOrExporterRole string) {

record, err := metaDB.GetMigrationStatusRecord()
if err != nil {
utils.ErrExit("exit if already cutover: load migration status record: %s", err)
utils.ErrExit("error getting migration status record to check cutover: %s", err)
}
cTAlreadyCompleted := "cutover already completed for this migration, aborting..."
cSRAlreadyCompleted := "cutover to source-replica already completed for this migration, aborting..."
Expand Down
3 changes: 2 additions & 1 deletion yb-voyager/cmd/cutoverStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/yugabyte/yb-voyager/yb-voyager/src/utils"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func checkAndReportCutoverStatus() {

msr, err := metaDB.GetMigrationStatusRecord()
if err != nil {
utils.ErrExit("analyze schema report summary: load migration status record: %s", err)
utils.ErrExit("error getting migration status record: %s", err)
}
if msr.FallbackEnabled {
reportCutoverToSourceStatus()
Expand Down
2 changes: 1 addition & 1 deletion yb-voyager/cmd/endMigrationCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var endMigrationCmd = &cobra.Command{
}
err = validateEndMigrationFlags(cmd)
if err != nil {
utils.ErrExit(err.Error())
utils.ErrExit("failed to validate end-migration flags: %v", err.Error())
}

},
Expand Down
20 changes: 10 additions & 10 deletions yb-voyager/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,21 @@ func registerExportDataFlags(cmd *cobra.Command) {

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

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

func validateConflictsBetweenTableListFlags(tableList string, excludeTableList string) {
if tableList != "" && tableListFilePath != "" {
utils.ErrExit("Error: Only one of --table-list and --table-list-file-path are allowed")
utils.ErrExit("Error Only one of --table-list and --table-list-file-path are allowed")
}
if excludeTableList != "" && excludeTableListFilePath != "" {
utils.ErrExit("Error: Only one of --exclude-table-list and --exclude-table-list-file-path are allowed")
utils.ErrExit("Error Only one of --exclude-table-list and --exclude-table-list-file-path are allowed")
}
}

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

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

Expand All @@ -313,7 +313,7 @@ func validateOracleParams() {
source.Schema = strings.ToUpper(source.Schema)
}
if source.DBName == "" && source.DBSid == "" && source.TNSAlias == "" {
utils.ErrExit(`Error: one flag required out of "oracle-tns-alias", "source-db-name", "oracle-db-sid" required.`)
utils.ErrExit(`Error one flag required out of "oracle-tns-alias", "source-db-name", "oracle-db-sid" required.`)
} else if source.TNSAlias != "" {
//Priority order for Oracle: oracle-tns-alias > source-db-name > oracle-db-sid
// TODO: revisit voyager code wrt the priority among: sid, tnsalias, dbname
Expand All @@ -340,7 +340,7 @@ func validateOracleParams() {
utils.PrintAndLog("Using CDB SID for export.")
}
if source.DBName == "" {
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`)
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`)
}
}

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

Expand Down
Loading

0 comments on commit 411843a

Please sign in to comment.