Skip to content

Commit 45752f1

Browse files
authored
Merge pull request #24 from ThreeDotsLabs/not-found
More user friendly NotFound error
2 parents cb8b6fa + c1d2769 commit 45752f1

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tdl/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var app = &cli.App{
4040
if errors.As(err, &missingArgumentError{}) {
4141
fmt.Printf("%s. Usage:\n\n", err.Error())
4242
cli.ShowSubcommandHelpAndExit(c, 1)
43+
return
4344
}
4445

4546
userFacingErr := trainings.UserFacingError{}

trainings/init.go

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/pkg/errors"
1818
"github.com/sirupsen/logrus"
1919
"github.com/spf13/afero"
20+
"google.golang.org/grpc/codes"
21+
"google.golang.org/grpc/status"
2022
)
2123

2224
func (h *Handlers) Init(ctx context.Context, trainingName string, dir string) error {
@@ -131,6 +133,12 @@ func (h *Handlers) startTraining(
131133
},
132134
)
133135
if err != nil {
136+
if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
137+
return "", UserFacingError{
138+
Msg: fmt.Sprintf("Training '%v' not found", trainingName),
139+
SolutionHint: "Please check the correct training name on the website.\n\nIf you wanted to init the training in a separate directory, use this format:\n\n\ttdl training init <name> <directory>",
140+
}
141+
}
134142
return "", errors.Wrap(err, "start training gRPC call failed")
135143
}
136144

0 commit comments

Comments
 (0)