Skip to content

Commit

Permalink
generators: streamline errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Sep 4, 2023
1 parent f83b19c commit 642d020
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions generators/csharp.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ func GenerateCsharpSDK(cfg *GenerateCfg) error {
cfg.ParamTypeConverter = scTypeToCsharp
ctr, err := templateFromManifest(cfg)
if err != nil {
return err
return fmt.Errorf("failed to parse manifest into contract template: %v", err)
}

tmp, err := template.New("generate").Parse(csharpSrcTmpl)
if err != nil {
return err
return fmt.Errorf("failed to parse C# source template: %v", err)
}

err = tmp.Execute(cfg.ContractOutput, ctr)
if err != nil {
log.Fatal(err)
return fmt.Errorf("failed to generate C# code using template: %v", err)
}

wd, err := os.Getwd()
if err != nil {
return err
return fmt.Errorf("failed to get working directory: %v", err)
}

sdkLocation := wd + "/" + cfg.SdkDestination + upperFirst(cfg.Manifest.Name) + ".cs"
Expand Down
8 changes: 4 additions & 4 deletions generators/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ func GenerateJavaSDK(cfg *GenerateCfg) error {
cfg.ParamTypeConverter = scTypeToJava
ctr, err := templateFromManifest(cfg)
if err != nil {
return err
return fmt.Errorf("failed to parse manifest into contract template: %v", err)
}
ctr.Hash = strings.TrimPrefix(ctr.Hash, "0x")

tmp, err := template.New("generate").Parse(javaSrcTmpl)
if err != nil {
return err
return fmt.Errorf("failed to parse Java source template: %v", err)
}

err = tmp.Execute(cfg.ContractOutput, ctr)
if err != nil {
log.Fatal(err)
return fmt.Errorf("failed to generate Java code using template: %v", err)
}

wd, err := os.Getwd()
if err != nil {
return err
return fmt.Errorf("failed to get working directory: %v", err)
}

log.Infof("Created SDK for contract '%s' at %s with contract hash 0x%s", cfg.Manifest.Name, wd+"/"+cfg.SdkDestination, cfg.ContractHash.StringLE())
Expand Down
8 changes: 4 additions & 4 deletions generators/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ func GeneratePythonSDK(cfg *GenerateCfg) error {
cfg.ParamTypeConverter = scTypeToPython
ctr, err := templateFromManifest(cfg)
if err != nil {
return err
return fmt.Errorf("failed to parse manifest into contract template: %v", err)
}

tmp, err := template.New("generate").Parse(pythonSrcTmpl)
if err != nil {
return err
return fmt.Errorf("failed to parse Python source template: %v", err)
}

err = tmp.Execute(cfg.ContractOutput, ctr)
if err != nil {
log.Fatal(err)
return fmt.Errorf("failed to generate Python code using template: %v", err)
}

wd, err := os.Getwd()
if err != nil {
return err
return fmt.Errorf("failed to get working directory: %v", err)
}
sdkLocation := wd + "/" + cfg.SdkDestination + upperFirst(cfg.Manifest.Name)
log.Infof("Created SDK for contract '%s' at %s with contract hash 0x%s", cfg.Manifest.Name, sdkLocation, cfg.ContractHash.StringLE())
Expand Down

0 comments on commit 642d020

Please sign in to comment.