Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] ErrorAndExit deprecated #6337

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
correction - %w used for wrapping
  • Loading branch information
samkitshah1262 committed Oct 9, 2024
commit e17870dd479f1f9cc076a79f6880867c21bcf562
6 changes: 3 additions & 3 deletions tools/cli/admin_db_clean_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ func fixExecution(
execManager, err := initializeExecutionStore(c, execution.Execution.(entity.Entity).GetShardID())
defer execManager.Close()
if err != nil {
return invariant.ManagerFixResult{}, fmt.Errorf("Error in fix execution: %v", err)
return invariant.ManagerFixResult{}, fmt.Errorf("Error in fix execution: %w", err)
}
historyV2Mgr, err := initializeHistoryManager(c)
defer historyV2Mgr.Close()
if err != nil {
return invariant.ManagerFixResult{}, fmt.Errorf("Error in fix execution: %v", err)
return invariant.ManagerFixResult{}, fmt.Errorf("Error in fix execution: %w", err)
}
pr := persistence.NewPersistenceRetryer(
execManager,
Expand All @@ -156,7 +156,7 @@ func fixExecution(
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return invariant.ManagerFixResult{}, fmt.Errorf("Context not created: %v", err)
return invariant.ManagerFixResult{}, fmt.Errorf("Context not created: %w", err)
}
return invariant.NewInvariantManager(ivs).RunFixes(ctx, execution.Execution), nil
}
8 changes: 4 additions & 4 deletions tools/cli/admin_db_scan_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ func checkExecution(
execManager, err := initializeExecutionStore(c, common.WorkflowIDToHistoryShard(req.WorkflowID, numberOfShards))
defer execManager.Close()
if err != nil {
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in execution check: %v", err)
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in execution check: %w", err)
}
historyV2Mgr, err := initializeHistoryManager(c)
defer historyV2Mgr.Close()
if err != nil {
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in execution check: %v", err)
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in execution check: %w", err)
}
pr := persistence.NewPersistenceRetryer(
execManager,
Expand All @@ -158,12 +158,12 @@ func checkExecution(
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in creating context: %v", err)
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in creating context: %w", err)
}
execution, err := fetcher(ctx, pr, req)

if err != nil {
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in check execution: %v", err)
return nil, invariant.ManagerCheckResult{}, fmt.Errorf("Error in check execution: %w", err)
}

var ivs []invariant.Invariant
Expand Down
8 changes: 4 additions & 4 deletions tools/cli/admin_dlq_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ func AdminGetDLQMessages(c *cli.Context) error {

events, err := deserializeBatchEvents(task.GetHistoryTaskV2Attributes().GetEvents())
if err != nil {
return nil, fmt.Errorf("Error in deserializing batch events: %v", err)
return nil, fmt.Errorf("Error in deserializing batch events: %w", err)
}
newRunEvents, err := deserializeBatchEvents(task.GetHistoryTaskV2Attributes().GetNewRunEvents())
if err != nil {
return nil, fmt.Errorf("Error in deserializing new run batch events: %v", err)
return nil, fmt.Errorf("Error in deserializing new run batch events: %w", err)
}
domainName, err := getDomainName(info.DomainID)
if err != nil {
Expand Down Expand Up @@ -405,7 +405,7 @@ func readShardsFromStdin() chan int {
break
}
if err != nil {
fmt.Printf("Unable to read from stdin: %v", err)
fmt.Printf("Unable to read from stdin: %w", err)
continue
}
shard, err := strconv.ParseInt(strings.TrimSpace(line), 10, 64)
Expand Down Expand Up @@ -438,7 +438,7 @@ func deserializeBatchEvents(blob *types.DataBlob) ([]*types.HistoryEvent, error)
serializer := persistence.NewPayloadSerializer()
events, err := serializer.DeserializeBatchEvents(persistence.NewDataBlobFromInternal(blob))
if err != nil {
return nil, fmt.Errorf("Failed to decode DLQ history replication events: %v", err)
return nil, fmt.Errorf("Failed to decode DLQ history replication events: %w", err)
}
return events, nil
}
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/admin_elastic_search_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func generateCSVReport(reportFileName string, headers []string, tableData [][]st
}
_, err = f.WriteString(csvContent)
if err != nil {
fmt.Printf("Error write to file, err: %v", err)
fmt.Printf("Error write to file, err: %w", err)
}
return f.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/admin_failover_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func getFailoverWorkflowID(c *cli.Context) string {
func getOperator() (string, error) {
user, err := user.Current()
if err != nil {
return "", fmt.Errorf("Unable to get operator info %v", err)
return "", fmt.Errorf("Unable to get operator info %w", err)
}

return fmt.Sprintf("%s (username: %s)", user.Name, user.Username), nil
Expand Down
6 changes: 3 additions & 3 deletions tools/cli/admin_kafka_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func getOutputFile(outputFile string) (*os.File, error) {
}
f, err := os.Create(outputFile)
if err != nil {
return nil, fmt.Errorf("failed to create output file %v", err)
return nil, fmt.Errorf("failed to create output file %w", err)
}

return f, nil
return f, nil
}

func startReader(file *os.File, readerCh chan<- []byte) error {
Expand Down Expand Up @@ -411,7 +411,7 @@ func deserializeMessages(messages [][]byte, skipErrors bool) ([]*types.Replicati
}
replicationTasks = append(replicationTasks, thrift.ToReplicationTask(&task))
}
return replicationTasks, skipped, nil
return replicationTasks, skipped, nil
}

func decode(message []byte, val *replicator.ReplicationTask) error {
Expand Down
22 changes: 11 additions & 11 deletions tools/cli/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,47 +153,47 @@ func getDBFlags() []cli.Flag {
func initializeExecutionStore(c *cli.Context, shardID int) (persistence.ExecutionManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %v", err)
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
}
historyManager, err := factory.NewExecutionManager(shardID)
if err != nil {
return nil, fmt.Errorf("Failed to initialize history manager", err)
return nil, fmt.Errorf("Failed to initialize history manager %w", err)
}
return historyManager, nil
}

func initializeHistoryManager(c *cli.Context) (persistence.HistoryManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %v", err)
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
}
historyManager, err := factory.NewHistoryManager()
if err != nil {
return nil, fmt.Errorf("Failed to initialize history manager", err)
return nil, fmt.Errorf("Failed to initialize history manager %w", err)
}
return historyManager, nil
}

func initializeShardManager(c *cli.Context) (persistence.ShardManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %v", err)
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
}
shardManager, err := factory.NewShardManager()
if err != nil {
return nil, fmt.Errorf("Failed to initialize shard manager %v", err)
return nil, fmt.Errorf("Failed to initialize shard manager %w", err)
}
return shardManager, nil
}

func initializeDomainManager(c *cli.Context) (persistence.DomainManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %v", err)
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
}
domainManager, err := factory.NewDomainManager()
if err != nil {
return nil, fmt.Errorf("Failed to initialize domain manager: %v", err)
return nil, fmt.Errorf("Failed to initialize domain manager: %w", err)
}
return domainManager, nil
}
Expand All @@ -205,7 +205,7 @@ func getPersistenceFactory(c *cli.Context) (client.Factory, error) {
if persistenceFactory == nil {
persistenceFactory, err = initPersistenceFactory(c)
if err != nil {
return persistenceFactory, fmt.Errorf("%v", err)
return persistenceFactory, fmt.Errorf("%w", err)
}
}
return persistenceFactory, nil
Expand All @@ -232,7 +232,7 @@ func initPersistenceFactory(c *cli.Context) (client.Factory, error) {
defaultStore := cfg.Persistence.DataStores[cfg.Persistence.DefaultStore]
defaultStore, err = overrideDataStore(c, defaultStore)
if err != nil {
return nil, fmt.Errorf("Error in init persistence factory: %v", err)
return nil, fmt.Errorf("Error in init persistence factory: %w", err)
}
cfg.Persistence.DataStores[cfg.Persistence.DefaultStore] = defaultStore

Expand All @@ -259,7 +259,7 @@ func overrideDataStore(c *cli.Context, ds config.DataStore) (config.DataStore, e
var err error
ds, err = createDataStore(c)
if err != nil {
return config.DataStore{}, fmt.Errorf("Error in overriding data store: %v", err)
return config.DataStore{}, fmt.Errorf("Error in overriding data store: %w", err)
}
}

Expand Down
8 changes: 4 additions & 4 deletions tools/cli/domain_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (d *domainCLIImpl) UpdateDomain(c *cli.Context) error {
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return commoncli.Problem("Error in creating context: %v", err)
return commoncli.Problem("Error in creating context: ", err)
}
if c.IsSet(FlagActiveClusterName) {
activeCluster := c.String(FlagActiveClusterName)
Expand Down Expand Up @@ -315,7 +315,7 @@ func (d *domainCLIImpl) DeprecateDomain(c *cli.Context) error {
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return commoncli.Problem("Error in creating context: %v", err)
return commoncli.Problem("Error in creating context: ", err)
}
if !force {
wfc, err := getWorkflowClient(c)
Expand Down Expand Up @@ -401,7 +401,7 @@ func (d *domainCLIImpl) getAllDomains(c *cli.Context) ([]*types.DescribeDomainRe
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return nil, commoncli.Problem("Error in creating context: %v", err)
return nil, commoncli.Problem("Error in creating context: ", err)
}
for more := true; more; more = len(token) > 0 {
listRequest := &types.ListDomainsRequest{
Expand Down Expand Up @@ -431,7 +431,7 @@ func (d *domainCLIImpl) failover(c *cli.Context, domainName string, targetCluste
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return commoncli.Problem("Error in creating context: %v", err)
return commoncli.Problem("Error in creating context: ", err)
}
_, err = d.updateDomain(ctx, updateRequest)
return err
Expand Down
26 changes: 13 additions & 13 deletions tools/cli/domain_migration_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (d *domainMigrationCLIImpl) Validation(c *cli.Context) error {
errCh <- nil
}(i)
}

wg.Wait()
close(errCh)
for err := range errCh {
Expand Down Expand Up @@ -202,19 +202,19 @@ func (d *domainMigrationCLIImpl) DomainMetaDataCheck(c *cli.Context) (DomainMigr
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Error in Domain meta data check: %v", err)
return DomainMigrationRow{}, fmt.Errorf("Error in Domain meta data check: %w", err)
}
currResp, err := d.frontendClient.DescribeDomain(ctx, &types.DescribeDomainRequest{
Name: &domain,
})
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Could not describe old domain, Please check to see if old domain exists before migrating. %v", err)
return DomainMigrationRow{}, fmt.Errorf("Could not describe old domain, Please check to see if old domain exists before migrating. %w", err)
}
newResp, err := d.destinationClient.DescribeDomain(ctx, &types.DescribeDomainRequest{
Name: &newDomain,
})
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Could not describe new domain, Please check to see if new domain exists before migrating. %v", err)
return DomainMigrationRow{}, fmt.Errorf("Could not describe new domain, Please check to see if new domain exists before migrating. %w", err)
}
validationResult, mismatchedMetaData := metaDataValidation(currResp, newResp)
validationRow := DomainMigrationRow{
Expand Down Expand Up @@ -243,7 +243,7 @@ func metaDataValidation(currResp *types.DescribeDomainResponse, newResp *types.D
func (d *domainMigrationCLIImpl) DomainWorkFlowCheck(c *cli.Context) (DomainMigrationRow, error) {
countWorkFlows, err := d.countLongRunningWorkflow(c)
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Error in Domain flow check: %v", err)
return DomainMigrationRow{}, fmt.Errorf("Error in Domain flow check: %w", err)
}
check := countWorkFlows == 0
dmr := DomainMigrationRow{
Expand All @@ -266,11 +266,11 @@ func (d *domainMigrationCLIImpl) countLongRunningWorkflow(c *cli.Context) (int,
ctx, cancel, err := newContextForLongPoll(c)
defer cancel()
if err != nil {
return 0, fmt.Errorf("Error in creating long context: %v", err)
return 0, fmt.Errorf("Error in creating long context: %w", err)
}
response, err := d.frontendClient.CountWorkflowExecutions(ctx, request)
if err != nil {
return 0, fmt.Errorf("Failed to count workflow. %v", err)
return 0, fmt.Errorf("Failed to count workflow. %w", err)
}
return int(response.GetCount()), nil
}
Expand All @@ -279,7 +279,7 @@ func (d *domainMigrationCLIImpl) SearchAttributesChecker(c *cli.Context) (Domain
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Error in creating long context: %v", err)
return DomainMigrationRow{}, fmt.Errorf("Error in creating long context: %w", err)
}
// getting user provided search attributes
searchAttributes := c.StringSlice(FlagSearchAttribute)
Expand Down Expand Up @@ -309,13 +309,13 @@ func (d *domainMigrationCLIImpl) SearchAttributesChecker(c *cli.Context) (Domain
// getting search attributes for current domain
currentSearchAttributes, err := d.frontendClient.GetSearchAttributes(ctx)
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Unable to get search attributes for new domain. %v", err)
return DomainMigrationRow{}, fmt.Errorf("Unable to get search attributes for new domain. %w", err)
}

// getting search attributes for new domain
destinationSearchAttributes, err := d.destinationClient.GetSearchAttributes(ctx)
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Unable to get search attributes for new domain. %v", err)
return DomainMigrationRow{}, fmt.Errorf("Unable to get search attributes for new domain. %w", err)
}

currentSearchAttrs := currentSearchAttributes.Keys
Expand Down Expand Up @@ -375,11 +375,11 @@ func (d *domainMigrationCLIImpl) DynamicConfigCheck(c *cli.Context) (DomainMigra
ctx, cancel, err := newContext(c)
defer cancel()
if err != nil {
return DomainMigrationRow{}, fmt.Errorf("Failed to create context: %v", err)
return DomainMigrationRow{}, fmt.Errorf("Failed to create context: %w", err)
}
currentDomainID, err1 := getDomainID(ctx, currDomain, d.frontendClient)
destinationDomainID, err2 := getDomainID(ctx, newDomain, d.destinationClient)
if currentDomainID == "" || err1 != nil{
if currentDomainID == "" || err1 != nil {
return DomainMigrationRow{}, fmt.Errorf("Failed to get domainID for the current domain. %v", nil)
}

Expand Down Expand Up @@ -529,7 +529,7 @@ func (d *domainMigrationCLIImpl) DynamicConfigCheck(c *cli.Context) (DomainMigra
func getDomainID(c context.Context, domain string, client frontend.Client) (string, error) {
resp, err := client.DescribeDomain(c, &types.DescribeDomainRequest{Name: &domain})
if err != nil {
return "", fmt.Errorf("Failed to describe domain. %v", err)
return "", fmt.Errorf("Failed to describe domain. %w", err)
}

return resp.DomainInfo.GetUUID(), nil
Expand Down
Loading
Loading