Skip to content

Commit d47a687

Browse files
Switch to structured error
1 parent 235005d commit d47a687

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

commands/cmderrors/cmderrors.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ func (e *UnknownProfileError) GRPCStatus() *status.Status {
211211
return status.New(codes.NotFound, e.Error())
212212
}
213213

214+
// DuplicateProfileError is returned when the profile is a duplicate of an already existing one
215+
type DuplicateProfileError struct {
216+
Profile string
217+
}
218+
219+
func (e *DuplicateProfileError) Error() string {
220+
return i18n.Tr("Profile '%s' already exists", e.Profile)
221+
}
222+
223+
// GRPCStatus converts the error into a *status.Status
224+
func (e *DuplicateProfileError) GRPCStatus() *status.Status {
225+
return status.New(codes.NotFound, e.Error())
226+
}
227+
214228
// InvalidProfileError is returned when the profile has errors
215229
type InvalidProfileError struct {
216230
Cause error

commands/service_profile_init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (s *arduinoCoreServerImpl) InitProfile(ctx context.Context, req *rpc.InitPr
5757

5858
// Check that the profile name is unique
5959
if profile, _ := sk.GetProfile(req.ProfileName); profile != nil {
60-
return nil, fmt.Errorf("%s: the profile already exists", req.ProfileName)
60+
return nil, &cmderrors.DuplicateProfileError{Profile: req.ProfileName}
6161
}
6262

6363
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())

0 commit comments

Comments
 (0)