Skip to content

Commit bc19916

Browse files
authored
Merge pull request #449 from oasisprotocol/kostko/fix/build-err-output
Clear any previously set errors for Docker env
2 parents 1bf6936 + 211aeba commit bc19916

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

build/env/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (de *DockerEnv) AddDirectory(path string) {
100100

101101
// WrapCommand implements ExecEnv.
102102
func (de *DockerEnv) WrapCommand(cmd *exec.Cmd) error {
103+
cmd.Err = nil // May be set by a previous exec.Command invocation.
103104
origArgs := cmd.Args
104105

105106
var err error

cmd/rofl/build/build.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
Use: "build",
4444
Short: "Build a ROFL application",
4545
Args: cobra.NoArgs,
46-
Run: func(_ *cobra.Command, _ []string) {
46+
RunE: func(_ *cobra.Command, _ []string) error {
4747
cfg := cliConfig.Global()
4848
npa := common.GetNPASelection(cfg)
4949
manifest, deployment := roflCommon.LoadManifestAndSetNPA(cfg, npa, deploymentName, &roflCommon.ManifestOptions{
@@ -72,7 +72,7 @@ var (
7272
// Prepare temporary build directory.
7373
tmpDir, err := os.MkdirTemp("", "oasis-build")
7474
if err != nil {
75-
cobra.CheckErr(fmt.Errorf("failed to create temporary build directory: %w", err))
75+
return fmt.Errorf("failed to create temporary build directory: %w", err)
7676
}
7777
defer os.RemoveAll(tmpDir)
7878

@@ -84,7 +84,7 @@ var (
8484
var baseDir string
8585
baseDir, err = env.GetBasedir()
8686
if err != nil {
87-
cobra.CheckErr(fmt.Sprintf("failed to determine base directory: %s", err))
87+
return fmt.Errorf("failed to determine base directory: %w", err)
8888
}
8989

9090
dockerEnv := env.NewDockerEnv(
@@ -97,7 +97,7 @@ var (
9797
}
9898

9999
if !buildEnv.IsAvailable() {
100-
cobra.CheckErr(fmt.Sprintf("Build environment '%s' is not available. Make sure it is installed.", buildEnv))
100+
return fmt.Errorf("build environment '%s' is not available", buildEnv)
101101
}
102102

103103
bnd := &bundle.Bundle{
@@ -120,8 +120,7 @@ var (
120120
case buildRofl.TEETypeSGX:
121121
// SGX.
122122
if manifest.Kind != buildRofl.AppKindRaw {
123-
fmt.Printf("unsupported app kind for SGX TEE: %s\n", manifest.Kind)
124-
return
123+
return fmt.Errorf("unsupported app kind for SGX TEE: %s", manifest.Kind)
125124
}
126125

127126
sgxBuild(buildEnv, npa, manifest, deployment, bnd)
@@ -134,12 +133,10 @@ var (
134133
err = tdxBuildContainer(buildEnv, tmpDir, npa, manifest, deployment, bnd)
135134
}
136135
default:
137-
fmt.Printf("unsupported TEE kind: %s\n", manifest.TEE)
138-
return
136+
return fmt.Errorf("unsupported TEE kind: %s", manifest.TEE)
139137
}
140138
if err != nil {
141-
fmt.Printf("%s\n", err)
142-
return
139+
return err
143140
}
144141

145142
runScript(manifest, buildRofl.ScriptBuildPost)
@@ -150,8 +147,7 @@ var (
150147
outFn = outputFn
151148
}
152149
if err = bnd.Write(outFn); err != nil {
153-
fmt.Printf("failed to write output bundle: %s\n", err)
154-
return
150+
return fmt.Errorf("failed to write output bundle: %s", err)
155151
}
156152

157153
fmt.Printf("ROFL app built and bundle written to '%s'.\n", outFn)
@@ -160,8 +156,7 @@ var (
160156

161157
ids, err := roflCommon.ComputeEnclaveIdentity(bnd, "")
162158
if err != nil {
163-
fmt.Printf("%s\n", err)
164-
return
159+
return err
165160
}
166161

167162
// Setup some post-bundle environment variables.
@@ -206,7 +201,7 @@ var (
206201
if !maps.Equal(buildEnclaves, latestManifestEnclaves) {
207202
fmt.Println("Built enclave identities DIFFER from latest manifest enclave identities!")
208203
showIdentityDiff(buildEnclaves, latestManifestEnclaves, "Built", "Manifest")
209-
cobra.CheckErr(fmt.Errorf("enclave identity verification failed"))
204+
return fmt.Errorf("enclave identity verification failed")
210205
}
211206

212207
fmt.Println("Built enclave identities MATCH latest manifest enclave identities.")
@@ -219,17 +214,19 @@ var (
219214
ctx := context.Background()
220215
var cfgEnclaves map[sgx.EnclaveIdentity]struct{}
221216
cfgEnclaves, err = roflCommon.GetRegisteredEnclaves(ctx, deployment.AppID, npa)
222-
cobra.CheckErr(err)
217+
if err != nil {
218+
return err
219+
}
223220

224221
if !maps.Equal(allManifestEnclaves, cfgEnclaves) {
225222
fmt.Println("Manifest enclave identities DIFFER from on-chain enclave identities!")
226223
showIdentityDiff(allManifestEnclaves, cfgEnclaves, "Manifest", "On-chain")
227-
cobra.CheckErr(fmt.Errorf("enclave identity verification failed"))
224+
return fmt.Errorf("enclave identity verification failed")
228225
}
229226

230227
fmt.Println("Manifest enclave identities MATCH on-chain enclave identities.")
231228
}
232-
return
229+
return nil
233230
}
234231

235232
// Override the update manifest flag in case the policy does not exist.
@@ -267,11 +264,12 @@ var (
267264
}
268265

269266
if err = manifest.Save(); err != nil {
270-
cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err))
267+
return fmt.Errorf("failed to update manifest: %w", err)
271268
}
272269

273270
fmt.Printf("Run `oasis rofl update` to update your ROFL app's on-chain configuration.\n")
274271
}
272+
return nil
275273
},
276274
}
277275
)

0 commit comments

Comments
 (0)