@@ -54,7 +54,12 @@ func (app *App) Run(cmd string, args map[string]interface{}, opts map[string]int
54
54
return nil , err
55
55
}
56
56
57
- return jr ()
57
+ res , err := jr ()
58
+ if err != nil {
59
+ return nil , err
60
+ }
61
+
62
+ return res , nil
58
63
}
59
64
60
65
func (app * App ) run (l * EventLogger , cmd string , args map [string ]interface {}, streamOutput bool ) (* Result , error ) {
@@ -66,17 +71,30 @@ func (app *App) run(l *EventLogger, cmd string, args map[string]interface{}, str
66
71
67
72
jr , err := app .Job (l , cmd , args , args , nil , streamOutput )
68
73
if err != nil {
74
+ if cmd != "" {
75
+ return nil , xerrors .Errorf ("job %q: %w" , cmd , err )
76
+ }
77
+ return nil , err
78
+ }
79
+
80
+ res , err := jr ()
81
+ if err != nil {
82
+ if cmd != "" {
83
+ return nil , xerrors .Errorf ("job %q: %w" , cmd , err )
84
+ }
69
85
return nil , err
70
86
}
71
87
72
- return jr ()
88
+ return res , nil
73
89
}
74
90
75
91
func (app * App ) Job (l * EventLogger , cmd string , args map [string ]interface {}, opts map [string ]interface {}, f SetOptsFunc , streamOutput bool ) (func () (* Result , error ), error ) {
76
92
jobByName := app .JobByName
77
93
78
- j , ok := jobByName [cmd ]
79
- if ! ok {
94
+ j , cmdDefined := jobByName [cmd ]
95
+ if ! cmdDefined {
96
+ var ok bool
97
+
80
98
j , ok = jobByName ["" ]
81
99
if ! ok {
82
100
return nil , fmt .Errorf ("command %q not found" , cmd )
@@ -213,7 +231,11 @@ func (app *App) Job(l *EventLogger, cmd string, args map[string]interface{}, opt
213
231
}
214
232
215
233
if err == nil {
216
- return nil , fmt .Errorf (NoRunMessage )
234
+ if ! cmdDefined {
235
+ return nil , xerrors .Errorf ("job %q is not defined" , cmd )
236
+ }
237
+
238
+ return nil , errors .New (NoRunMessage )
217
239
}
218
240
} else {
219
241
// The job contained job or step(s).
@@ -602,7 +624,7 @@ func (app *App) execTest(t *testing.T, test Test) *Result {
602
624
res , err = testApp .execTestCase (test , c )
603
625
if err != nil {
604
626
app .PrintError (err )
605
- t .Fatalf ("%v" , err )
627
+ t .Fatalf ("%s: %v" , c . SourceLocator . Range () , err )
606
628
}
607
629
})
608
630
}
@@ -967,7 +989,7 @@ func (app *App) execJobSteps(l *EventLogger, jobCtx *JobContext, results map[str
967
989
f := func () (* Result , error ) {
968
990
res , err := app .runJobAndUpdateContext (l , & stepCtx , eitherJobRun {static : & s .Run }, m , streamOutput )
969
991
if err != nil {
970
- return res , err
992
+ return res , xerrors . Errorf ( "step %q: %w" , s . Name , err )
971
993
}
972
994
973
995
m .Lock ()
@@ -1248,12 +1270,12 @@ func (app *App) createJobContext(cc *HCL2Config, j JobSpec, givenParams map[stri
1248
1270
1249
1271
globalParams , err := setParameterValues ("global parameter" , ctx , cc .Parameters , givenParams )
1250
1272
if err != nil {
1251
- return nil , fmt . Errorf ( "job %q: %w" , j . Name , err )
1273
+ return nil , err
1252
1274
}
1253
1275
1254
1276
localParams , err := setParameterValues ("parameter" , ctx , j .Parameters , givenParams )
1255
1277
if err != nil {
1256
- return nil , fmt . Errorf ( "job %q: %w" , j . Name , err )
1278
+ return nil , err
1257
1279
}
1258
1280
1259
1281
params := map [string ]cty.Value {}
@@ -1275,12 +1297,12 @@ func (app *App) createJobContext(cc *HCL2Config, j JobSpec, givenParams map[stri
1275
1297
1276
1298
globalOpts , err := setOptionValues ("global option" , ctx , cc .Options , givenOpts , f )
1277
1299
if err != nil {
1278
- return nil , fmt . Errorf ( "job %q: %w" , j . Name , err )
1300
+ return nil , err
1279
1301
}
1280
1302
1281
1303
localOpts , err := setOptionValues ("option" , ctx , j .Options , givenOpts , f )
1282
1304
if err != nil {
1283
- return nil , fmt . Errorf ( "job %q: %w" , j . Name , err )
1305
+ return nil , err
1284
1306
}
1285
1307
1286
1308
opts := map [string ]cty.Value {}
@@ -1410,7 +1432,7 @@ func (app *App) getConfigs(jobCtx *JobContext, cc *HCL2Config, j JobSpec, confTy
1410
1432
yamlData , err = ioutil .ReadFile (source .Path )
1411
1433
if err != nil {
1412
1434
if source .Default == nil {
1413
- return cty .NilVal , fmt .Errorf ("job %q: % s %q: source %d: %w" , j . Name , confType , confSpec .Name , sourceIdx , err )
1435
+ return cty .NilVal , fmt .Errorf ("% s %q: source %d: %w" , confType , confSpec .Name , sourceIdx , err )
1414
1436
}
1415
1437
1416
1438
yamlData = []byte (* source .Default )
@@ -1434,7 +1456,7 @@ func (app *App) getConfigs(jobCtx *JobContext, cc *HCL2Config, j JobSpec, confTy
1434
1456
1435
1457
res , err := app .run (nil , source .Name , args , false )
1436
1458
if err != nil {
1437
- return cty .NilVal , err
1459
+ return cty .NilVal , xerrors . Errorf ( "%s %q: source %d: %w" , confType , confSpec . Name , sourceIdx , err )
1438
1460
}
1439
1461
1440
1462
yamlData = []byte (res .Stdout )
0 commit comments