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

Enrich error messages #673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 12 additions & 8 deletions add-chain/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func readAddressesFromChain(addresses *superchain.AddressList, l1RpcUrl string,
if err != nil {
address, err = validation.CastCall(addresses.OptimismPortalProxy, "guardian()(address)", nil, l1RpcUrl)
if err != nil {
return fmt.Errorf("could not retrieve address for Guardian %w", err)
return fmt.Errorf("could not retrieve Guardian address from OptimismPortalProxy at %s: %w", addresses.OptimismPortalProxy, err)
}
}
addresses.Guardian = superchain.MustHexToAddress(address[0])
Expand Down Expand Up @@ -102,29 +102,33 @@ func readAddressesFromJSON(addressList *superchain.AddressList, deploymentsDir s
deployFilePath := filepath.Join(deploymentsDir)
fileInfo, err := os.Stat(deployFilePath)
if err != nil {
return fmt.Errorf("invalid deployment filepath provided: %w", err)
return fmt.Errorf("invalid deployment filepath provided (%s): %w", deployFilePath, err)
}

if fileInfo.IsDir() {
deployFilePath = filepath.Join(deploymentsDir, ".deploy")
_, err = os.Stat(deployFilePath)
if err != nil {
// Use legacy deployment artifact schema
fmt.Printf("failed to find .deploy file. Will look for legacy .json files in %s.", deploymentsDir)
contractAddresses := make(map[string]string)
fmt.Printf("failed to find .deploy file. Will look for legacy .json files")
files, _ := os.ReadDir(deploymentsDir)
files, err := os.ReadDir(deploymentsDir)
if err != nil {
return fmt.Errorf("failed to read contents of directory (%s): %w", deploymentsDir, err)
}
for _, file := range files {
if file.IsDir() {
continue
}
contractName := strings.TrimSuffix(file.Name(), filepath.Ext(file.Name()))
fileContents, err := os.ReadFile(filepath.Join(deploymentsDir, file.Name()))
filePath := filepath.Join(deploymentsDir, file.Name())
fileContents, err := os.ReadFile(filePath)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
return fmt.Errorf("failed to read file (%s): %w", filePath, err)
}
var data AddressData
if err = json.Unmarshal(fileContents, &data); err != nil {
return fmt.Errorf("failed to unmarshal json: %w", err)
return fmt.Errorf("failed to unmarshal JSON in file (%s): %w", filePath, err)
}
contractAddresses[contractName] = data.Address
err = mapToAddressList(contractAddresses, addressList)
Expand All @@ -138,7 +142,7 @@ func readAddressesFromJSON(addressList *superchain.AddressList, deploymentsDir s

rawData, err := os.ReadFile(deployFilePath)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
return fmt.Errorf("failed to read file %s: %w", deployFilePath, err)
}

if err = json.Unmarshal(rawData, &addressList); err != nil {
Expand Down
26 changes: 13 additions & 13 deletions add-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,35 @@ func entrypoint(ctx *cli.Context) error {
// Check if superchain target directory exists
targetDir := filepath.Join(superchainRepoRoot, "superchain", "configs", superchainTarget)
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
return fmt.Errorf("superchain target directory not found. Please follow instructions to add a superchain target in CONTRIBUTING.md: %s", targetDir)
return fmt.Errorf("superchain target directory not found: %s. Please add the target in CONTRIBUTING.md", targetDir)
Copy link
Collaborator

@bitwiseguy bitwiseguy Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reword this slightly:

fmt.Errorf("superchain target directory not found: %s. Please follow instructions in CONTRIBUTING.md to add a superchain target", targetDir)

}

l1RpcUrl, err := config.GetL1RpcUrl(superchainTarget)
if err != nil {
return fmt.Errorf("failed to retrieve L1 rpc url: %w", err)
return fmt.Errorf("failed to retrieve L1 rpc URL for superchain target %s: %w", superchainTarget, err)
}

var addresses superchain.AddressList
err = readAddressesFromJSON(&addresses, deploymentsDir)
if err != nil {
return fmt.Errorf("failed to read addresses from JSON files: %w", err)
return fmt.Errorf("failed to read addresses from JSON files in directory %s: %w", deploymentsDir, err)
}

isFaultProofs, err := inferIsFaultProofs(addresses.SystemConfigProxy, addresses.OptimismPortalProxy, l1RpcUrl)
if err != nil {
return fmt.Errorf("failed to infer fault proofs status of chain: %w", err)
return fmt.Errorf("failed to infer fault proofs status of chain using SystemConfigProxy (%s) and OptimismPortalProxy (%s): %w", addresses.SystemConfigProxy, addresses.OptimismPortalProxy, err)
}

rollupConfig, err := config.ConstructChainConfig(rollupConfigPath, genesisPath, chainName, publicRPC, sequencerRPC, explorer, superchainLevel, standardChainCandidate)
if err != nil {
return fmt.Errorf("failed to construct rollup config: %w", err)
return fmt.Errorf("failed to construct rollup config from path %s: %w", rollupConfigPath, err)
}

fmt.Printf("✅ Rollup config successfully constructed\n")

err = readAddressesFromChain(&addresses, l1RpcUrl, isFaultProofs)
if err != nil {
return fmt.Errorf("failed to read addresses from chain: %w", err)
return fmt.Errorf("failed to read addresses from chain at %s: %w", l1RpcUrl, err)
}

fmt.Printf("✅ Addresses read from chain\n")
Expand All @@ -169,18 +169,18 @@ func entrypoint(ctx *cli.Context) error {

l1RpcUrl, err = config.GetL1RpcUrl(superchainTarget)
if err != nil {
return fmt.Errorf("error getting l1RpcUrl: %w", err)
return fmt.Errorf("error retrieving L1 RPC URL for superchain target %s: %w", superchainTarget, err)
}
gpt, err := getGasPayingToken(l1RpcUrl, addresses.SystemConfigProxy)
if err != nil {
return fmt.Errorf("error inferring gas paying token: %w", err)
return fmt.Errorf("error inferring gas paying token using SystemConfigProxy address %s: %w", addresses.SystemConfigProxy, err)
}
rollupConfig.GasPayingToken = gpt

targetFilePath := filepath.Join(targetDir, chainShortName+".toml")
err = config.WriteChainConfigTOML(rollupConfig, targetFilePath)
if err != nil {
return fmt.Errorf("error generating chain config %s.toml file: %w", chainShortName, err)
return fmt.Errorf("error generating chain config file (%s.toml): %w", chainShortName, err)
}

fmt.Printf("✅ Wrote config for new chain to %s\n", targetFilePath)
Expand All @@ -192,17 +192,17 @@ func entrypoint(ctx *cli.Context) error {
genesisValidationInputsDir := filepath.Join(superchainRepoRoot, "validation", "genesis", "validation-inputs", folderName)
err = os.MkdirAll(genesisValidationInputsDir, os.ModePerm)
if err != nil {
return err
return fmt.Errorf("error creating directory for genesis validation inputs at %s: %w", genesisValidationInputsDir, err)
}
err = copyDeployConfigFile(deployConfigPath, genesisValidationInputsDir)
if err != nil {
return fmt.Errorf("error copying deploy-config json file: %w", err)
return fmt.Errorf("error copying deploy-config file from %s to validation inputs directory %s: %w", deployConfigPath, genesisValidationInputsDir, err)
}
fmt.Printf("✅ Copied deploy-config json file to validation module\n")
fmt.Printf("✅ Copied deploy-config JSON file to validation module\n")

err = writeGenesisValidationMetadata(genesisCreationCommit, genesisValidationInputsDir)
if err != nil {
return fmt.Errorf("error writing genesis validation metadata file: %w", err)
return fmt.Errorf("error writing genesis validation metadata file in directory %s: %w", genesisValidationInputsDir, err)
}
fmt.Printf("✅ Wrote genesis validation metadata file\n")

Expand Down