Skip to content

Commit 5d12eb1

Browse files
Switch to structured error
1 parent acbd927 commit 5d12eb1

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
@@ -212,6 +212,20 @@ func (e *UnknownProfileError) GRPCStatus() *status.Status {
212212
return status.New(codes.NotFound, e.Error())
213213
}
214214

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