Skip to content

Commit

Permalink
multi project push error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcador committed Nov 24, 2020
1 parent 776d0b4 commit 7ffed3c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func uploadContracts(rest *rest.Rest) error {
)
}

pushErrors := make(map[string]*userError.UserError)

for projectSlug, projectConfiguration := range projectConfigurations {
logrus.Info(colorizer.Sprintf(
"Pushing Smart Contracts for project: %s",
Expand Down Expand Up @@ -103,7 +105,7 @@ func uploadContracts(rest *rest.Rest) error {
}
if numberOfContractsWithANetwork == 0 {
if deploymentProvider.GetProviderName() == providers.OpenZeppelinDeploymentProvider {
return userError.NewUserError(
pushErrors[projectSlug] = userError.NewUserError(
fmt.Errorf("no contracts with a netowrk found in build dir: %s", providerConfig.AbsoluteBuildDirectoryPath()),
colorizer.Sprintf("No migrated contracts detected in build directory: %s. This can happen when no contracts have been migrated yet.\n"+
"There is currently an issue with exporting networks for regular contracts.\nThe OpenZeppelin team has come up with a workaround,"+
Expand All @@ -115,13 +117,15 @@ func uploadContracts(rest *rest.Rest) error {
colorizer.Bold(colorizer.Green("https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1555#issuecomment-644536123")),
),
)
continue
}
return userError.NewUserError(
pushErrors[projectSlug] = userError.NewUserError(
fmt.Errorf("no contracts with a netowrk found in build dir: %s", providerConfig.AbsoluteBuildDirectoryPath()),
colorizer.Sprintf("No migrated contracts detected in build directory: %s. This can happen when no contracts have been migrated yet.",
colorizer.Bold(colorizer.Red(providerConfig.AbsoluteBuildDirectoryPath())),
),
)
continue
}

logrus.Info("We have detected the following Smart Contracts:")
Expand All @@ -148,17 +152,19 @@ func uploadContracts(rest *rest.Rest) error {
s.Stop()

if err != nil {
return userError.NewUserError(
pushErrors[projectSlug] = userError.NewUserError(
fmt.Errorf("failed uploading contracts: %s", err),
"Couldn't push contracts to the Tenderly servers",
)
continue
}

if response.Error != nil {
return userError.NewUserError(
pushErrors[projectSlug] = userError.NewUserError(
fmt.Errorf("api error uploading contracts: %s", response.Error.Slug),
response.Error.Message,
)
continue
}

if len(response.Contracts) != numberOfContractsWithANetwork {
Expand Down Expand Up @@ -187,13 +193,14 @@ func uploadContracts(rest *rest.Rest) error {
}
}

return userError.NewUserError(
pushErrors[projectSlug] = userError.NewUserError(
fmt.Errorf("unexpected number of pushed contracts. Got: %d expected: %d", len(response.Contracts), len(contracts)),
fmt.Sprintf("Some of the contracts haven't been pushed. This can happen when the contract isn't deployed to a supported network or some other error might have occurred. "+
"Below is the list with all the contracts that weren't pushed successfully:\n%s",
strings.Join(nonPushedContracts, "\n"),
),
)
continue
}

username := config.GetString(config.Username)
Expand All @@ -210,6 +217,14 @@ func uploadContracts(rest *rest.Rest) error {
))
}

for k, v := range pushErrors {
userError.LogErrorf(fmt.Sprintf("Push for %s failed with error: ", k)+"%s", v)
}

if len(pushErrors) > 0 {
return userError.NewUserError(errors.New("some project uploads failed"), "Some of the project pushes were not successful. You can see the list above")
}

return nil
}

Expand Down

0 comments on commit 7ffed3c

Please sign in to comment.