diff --git a/client/internal/profilemanager/service.go b/client/internal/profilemanager/service.go index d5a5b8557..5ddd11b04 100644 --- a/client/internal/profilemanager/service.go +++ b/client/internal/profilemanager/service.go @@ -575,8 +575,8 @@ func (s *ServiceManager) activeProfileID() (ID, bool) { } // ResolveProfile turns a user-supplied handle into a Profile. Resolution -// precedence is: exact ID match, then unique ID prefix, then unique exact -// name. Ambiguous matches return *ErrAmbiguousHandle so callers can +// precedence is: exact ID match, then unique exact name, then unique ID +// prefix. Ambiguous matches return *ErrAmbiguousHandle so callers can // surface the candidates. func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, error) { if handle == "" { @@ -594,6 +594,23 @@ func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, erro } } + var nameMatches []Profile + for i := range profiles { + if profiles[i].Name == handle { + nameMatches = append(nameMatches, profiles[i]) + } + } + if len(nameMatches) == 1 { + return &nameMatches[0], nil + } + if len(nameMatches) > 1 { + return nil, &ErrAmbiguousHandle{ + Handle: handle, + Candidates: nameMatches, + Kind: AmbiguityKindName, + } + } + // ID prefix match. Skip the default profile so `select d` does not // accidentally pick it via prefix. var prefixMatches []Profile @@ -616,22 +633,5 @@ func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, erro } } - var nameMatches []Profile - for i := range profiles { - if profiles[i].Name == handle { - nameMatches = append(nameMatches, profiles[i]) - } - } - if len(nameMatches) == 1 { - return &nameMatches[0], nil - } - if len(nameMatches) > 1 { - return nil, &ErrAmbiguousHandle{ - Handle: handle, - Candidates: nameMatches, - Kind: AmbiguityKindName, - } - } - return nil, ErrProfileNotFound } diff --git a/client/server/server.go b/client/server/server.go index ec53c309d..a4d53a823 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -78,7 +78,7 @@ type Server struct { // changed by connectWithRetryRuns goroutine exit — for that // (goroutine-still-alive) check, see connectionGoroutineRunning() which // derives from clientGiveUpChan close state. Protected by s.mutex. - clientRunning bool + clientRunning bool clientRunningChan chan struct{} clientGiveUpChan chan struct{} // closed when connectWithRetryRuns goroutine exits @@ -375,7 +375,7 @@ func (s *Server) SetConfig(callerCtx context.Context, msg *proto.SetConfigReques return nil, err } - config, err := setConfigInputFromRequest(msg) + config, err := s.setConfigInputFromRequest(msg) if err != nil { return nil, err } @@ -398,17 +398,18 @@ func (s *Server) SetConfig(callerCtx context.Context, msg *proto.SetConfigReques // field is its own optional case. Returns the resolved ConfigInput // and a non-nil error only when the active profile file path cannot // be determined. -func setConfigInputFromRequest(msg *proto.SetConfigRequest) (profilemanager.ConfigInput, error) { +func (s *Server) setConfigInputFromRequest(msg *proto.SetConfigRequest) (profilemanager.ConfigInput, error) { var config profilemanager.ConfigInput resolved, err := s.resolveProfileHandle(msg.ProfileName, msg.Username) if err != nil { log.Errorf("failed to resolve profile %q: %v", msg.ProfileName, err) - return nil, err + return config, err } profPath := resolved.Path if profPath == "" { profPath = profilemanager.DefaultConfigPath + } config.ConfigPath = profPath if msg.ManagementUrl != "" {