Skip to content

Commit

Permalink
Fix bug in get instance query
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-samfira committed May 11, 2022
1 parent f428e86 commit 209347e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions database/sql/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ func (s *sqlDatabase) getInstanceByID(ctx context.Context, instanceID string) (I
func (s *sqlDatabase) getPoolInstanceByName(ctx context.Context, poolID string, instanceName string) (Instance, error) {
pool, err := s.getPoolByID(ctx, poolID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return Instance{}, errors.Wrap(runnerErrors.ErrNotFound, "fetching instance")
}
return Instance{}, errors.Wrap(err, "fetching pool")
}

Expand All @@ -78,7 +75,10 @@ func (s *sqlDatabase) getPoolInstanceByName(ctx context.Context, poolID string,
Where("name = ? and pool_id = ?", instanceName, pool.ID).
First(&instance)
if q.Error != nil {
return Instance{}, errors.Wrap(q.Error, "fetching instance")
if errors.Is(q.Error, gorm.ErrRecordNotFound) {
return Instance{}, errors.Wrap(runnerErrors.ErrNotFound, "fetching pool instance by name")
}
return Instance{}, errors.Wrap(q.Error, "fetching pool instance by name")
}
return instance, nil
}
Expand All @@ -99,7 +99,10 @@ func (s *sqlDatabase) getInstanceByName(ctx context.Context, instanceName string
Where("name = ?", instanceName).
First(&instance)
if q.Error != nil {
return Instance{}, errors.Wrap(q.Error, "fetching instance")
if errors.Is(q.Error, gorm.ErrRecordNotFound) {
return Instance{}, errors.Wrap(runnerErrors.ErrNotFound, "fetching instance by name")
}
return Instance{}, errors.Wrap(q.Error, "fetching instance by name")
}
return instance, nil
}
Expand Down
2 changes: 1 addition & 1 deletion runner/pool/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func (r *basePool) addPendingInstances() {
wg.Add(1)
go func(instance params.Instance) {
defer wg.Done()
log.Printf("creating instance %s in provider", instance.Name)
log.Printf("creating instance %s in pool %s", instance.Name, instance.PoolID)
if err := r.addInstanceToProvider(instance); err != nil {
log.Printf("failed to add instance to provider: %s", err)
errAsBytes := []byte(err.Error())
Expand Down

0 comments on commit 209347e

Please sign in to comment.