Skip to content

Commit eabff28

Browse files
committed
Improve error handling and fail on start-change/end-change when the change can't be located
1 parent 7eeb731 commit eabff28

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

cmd/endchange.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func EndChange(signals chan os.Signal, ready chan bool) int {
6565
defer cancel()
6666

6767
lf := log.Fields{}
68-
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_HAPPENING)
68+
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_HAPPENING, true)
6969
if err != nil {
7070
log.WithError(err).WithFields(lf).Error("failed to identify change")
7171
return 1
@@ -81,7 +81,7 @@ func EndChange(signals chan os.Signal, ready chan bool) int {
8181
},
8282
})
8383
if err != nil {
84-
log.WithContext(ctx).WithFields(lf).WithError(err).Error("failed to start change")
84+
log.WithContext(ctx).WithFields(lf).WithError(err).Error("failed to end change")
8585
return 1
8686
}
8787
log.WithContext(ctx).WithFields(lf).Info("processing")
@@ -93,7 +93,12 @@ func EndChange(signals chan os.Signal, ready chan bool) int {
9393
"edges": msg.NumEdges,
9494
}).Info("progress")
9595
}
96-
log.WithContext(ctx).WithFields(lf).Info("started change")
96+
if stream.Err() != nil {
97+
log.WithContext(ctx).WithFields(lf).WithError(stream.Err()).Error("failed to process end change")
98+
return 1
99+
}
100+
101+
log.WithContext(ctx).WithFields(lf).Info("finished change")
97102
return 0
98103
}
99104

cmd/getchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func GetChange(signals chan os.Signal, ready chan bool) int {
6767
defer cancel()
6868

6969
lf := log.Fields{}
70-
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus(sdp.ChangeStatus_value[viper.GetString("status")]))
70+
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus(sdp.ChangeStatus_value[viper.GetString("status")]), true)
7171
if err != nil {
7272
log.WithError(err).WithFields(lf).Error("failed to identify change")
7373
return 1

cmd/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func ensureToken(ctx context.Context, signals chan os.Signal) (context.Context,
185185
}
186186

187187
// getChangeUuid returns the UUID of a change, as selected by --uuid or --change, or a state with the specified status and having --ticket-link
188-
func getChangeUuid(ctx context.Context, expectedStatus sdp.ChangeStatus) (uuid.UUID, error) {
188+
func getChangeUuid(ctx context.Context, expectedStatus sdp.ChangeStatus, errNotFound bool) (uuid.UUID, error) {
189189
var changeUuid uuid.UUID
190190
var err error
191191

@@ -231,9 +231,9 @@ func getChangeUuid(ctx context.Context, expectedStatus sdp.ChangeStatus) (uuid.U
231231
}
232232
}
233233

234-
// if changeUuid == uuid.Nil {
235-
// return uuid.Nil, errors.New("no change specified; use one of --change, --ticket-link or --uuid")
236-
// }
234+
if errNotFound && changeUuid == uuid.Nil {
235+
return uuid.Nil, errors.New("no change specified; use one of --change, --ticket-link or --uuid")
236+
}
237237

238238
return changeUuid, nil
239239
}

cmd/startchange.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func StartChange(signals chan os.Signal, ready chan bool) int {
6565
defer cancel()
6666

6767
lf := log.Fields{}
68-
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_DEFINING)
68+
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_DEFINING, true)
6969
if err != nil {
7070
log.WithError(err).WithFields(lf).Error("failed to identify change")
7171
return 1
@@ -93,6 +93,11 @@ func StartChange(signals chan os.Signal, ready chan bool) int {
9393
"edges": msg.NumEdges,
9494
}).Info("progress")
9595
}
96+
if stream.Err() != nil {
97+
log.WithContext(ctx).WithFields(lf).WithError(stream.Err()).Error("failed to process start change")
98+
return 1
99+
}
100+
96101
log.WithContext(ctx).WithFields(lf).Info("started change")
97102
return 0
98103
}

cmd/submitplan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int {
228228
}
229229

230230
client := AuthenticatedChangesClient(ctx)
231-
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_DEFINING)
231+
changeUuid, err := getChangeUuid(ctx, sdp.ChangeStatus_CHANGE_STATUS_DEFINING, false)
232232
if err != nil {
233233
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to searching for existing changes")
234234
return 1

0 commit comments

Comments
 (0)