Commit 1aa7e74b authored by Mark Tyneway's avatar Mark Tyneway

op-bindings: modularize errors

parent 1023cd7b
...@@ -2,6 +2,7 @@ package hardhat ...@@ -2,6 +2,7 @@ package hardhat
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/fs" "io/fs"
"os" "os"
...@@ -12,6 +13,11 @@ import ( ...@@ -12,6 +13,11 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/solc" "github.com/ethereum-optimism/optimism/op-bindings/solc"
) )
var (
ErrCannotFindDeployment = errors.New("cannot find deployment")
ErrCannotFindArtifact = errors.New("cannot find artifact")
)
// `Hardhat` encapsulates all of the functionality required to interact // `Hardhat` encapsulates all of the functionality required to interact
// with hardhat style artifacts. // with hardhat style artifacts.
type Hardhat struct { type Hardhat struct {
...@@ -163,7 +169,7 @@ func (h *Hardhat) GetArtifact(name string) (*Artifact, error) { ...@@ -163,7 +169,7 @@ func (h *Hardhat) GetArtifact(name string) (*Artifact, error) {
return artifact, nil return artifact, nil
} }
} }
return nil, fmt.Errorf("cannot find artifact %s", name) return nil, fmt.Errorf("%w: %s", ErrCannotFindArtifact, name)
} }
for _, artifact := range h.artifacts { for _, artifact := range h.artifacts {
...@@ -172,7 +178,7 @@ func (h *Hardhat) GetArtifact(name string) (*Artifact, error) { ...@@ -172,7 +178,7 @@ func (h *Hardhat) GetArtifact(name string) (*Artifact, error) {
} }
} }
return nil, fmt.Errorf("cannot find artifact %s", name) return nil, fmt.Errorf("%w: %s", ErrCannotFindArtifact, name)
} }
// GetDeployment returns the deployment that corresponds to the contract. // GetDeployment returns the deployment that corresponds to the contract.
...@@ -188,7 +194,7 @@ func (h *Hardhat) GetDeployment(name string) (*Deployment, error) { ...@@ -188,7 +194,7 @@ func (h *Hardhat) GetDeployment(name string) (*Deployment, error) {
} }
} }
return nil, fmt.Errorf("cannot find deployment %s", name) return nil, fmt.Errorf("%w: %s", ErrCannotFindDeployment, name)
} }
// GetBuildInfo returns the build info that corresponds to the contract. // GetBuildInfo returns the build info that corresponds to the contract.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment