@@ -3,6 +3,8 @@ package trainings
33import (
44 "context"
55 "fmt"
6+ "google.golang.org/grpc/codes"
7+ "google.golang.org/grpc/status"
68 "io"
79 "os"
810 "path/filepath"
@@ -70,14 +72,24 @@ func (h *Handlers) run(ctx context.Context) (success bool, finished bool, err er
7072
7173 // todo - validate if exercise id == training exercise id? to ensure about consistency
7274 success , err = h .runExercise (ctx , trainingRootFs )
75+
76+ if isExerciseNoLongerAvailable (err ) {
77+ fmt .Println (color .YellowString ("We did update of the exercise code. Your local workspace is out of sync." ))
78+
79+ if ! internal .ConfirmPromptDefaultYes ("update your local workspace" ) {
80+ os .Exit (0 )
81+ }
82+
83+ finished , err = h .nextExercise (ctx , "" )
84+ return
85+ }
7386 if ! success || err != nil {
7487 return
7588 }
7689
7790 fmt .Println ()
7891 if ! internal .ConfirmPromptDefaultYes ("go to the next exercise" ) {
7992 os .Exit (0 )
80- return success , false , nil
8193 }
8294
8395 finished , err = h .nextExercise (ctx , h .config .ExerciseConfig (trainingRootFs ).ExerciseID )
@@ -88,6 +100,10 @@ func (h *Handlers) run(ctx context.Context) (success bool, finished bool, err er
88100 return
89101}
90102
103+ func isExerciseNoLongerAvailable (err error ) bool {
104+ return status .Code (errors .Cause (err )) == codes .NotFound
105+ }
106+
91107func (h * Handlers ) runExercise (ctx context.Context , trainingRootFs * afero.BasePathFs ) (bool , error ) {
92108 exerciseConfig := h .config .ExerciseConfig (trainingRootFs )
93109
@@ -138,7 +154,7 @@ func (h *Handlers) runExercise(ctx context.Context, trainingRootFs *afero.BasePa
138154 break
139155 }
140156 if err != nil {
141- logrus . WithError (err ). WithField ( "verification_id" , verificationID ). Panic ( "Internal error. " )
157+ return false , errors . Wrap (err , " error response from server " )
142158 }
143159
144160 if response .Finished {
0 commit comments