-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-474 Save resource error when not started #1514
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ type resourceManager struct { | |
type resourcePlaceholder struct { | ||
real interface{} | ||
config interface{} | ||
err error | ||
} | ||
|
||
type resourceManagerOptions struct { | ||
|
@@ -364,7 +365,8 @@ func (manager *resourceManager) completeConfig( | |
if c, ok := wrap.config.(config.Component); ok { | ||
iface, err := manager.processComponent(ctx, r, c, wrap.real, robot) | ||
if err != nil { | ||
manager.logger.Errorw("error building component", "error", err) | ||
manager.logger.Errorw("error building component", "resource", c.ResourceName(), "model", c.Model, "error", err) | ||
wrap.err = errors.Wrap(err, "component build error") | ||
continue | ||
} | ||
manager.resources.AddNode(r, iface) | ||
|
@@ -375,7 +377,8 @@ func (manager *resourceManager) completeConfig( | |
} else if rc, ok := wrap.config.(config.Remote); ok { | ||
rr, err := manager.processRemote(ctx, rc) | ||
if err != nil { | ||
manager.logger.Errorw("error connecting to remote", "error", err) | ||
manager.logger.Errorw("error connecting to remote", "remote", rc.Name, "error", err) | ||
wrap.err = errors.Wrap(err, "remote connection error") | ||
continue | ||
} | ||
manager.addRemote(ctx, rr, rc, robot) | ||
|
@@ -406,11 +409,14 @@ func (manager *resourceManager) completeConfig( | |
} | ||
s, ok := wrap.config.(config.Service) | ||
if !ok { | ||
manager.logger.Errorw("service config is not a service config", "resource", r) | ||
err := errors.New("service config is not a service config") | ||
manager.logger.Errorw(err.Error(), "resource", r) | ||
wrap.err = errors.Wrap(err, "service build error") | ||
} | ||
iface, err := manager.processService(ctx, s, wrap.real, robot) | ||
if err != nil { | ||
manager.logger.Errorw("error building service", "error", err) | ||
manager.logger.Errorw("error building service", "resource", s.ResourceName(), "model", s.Model, "error", err) | ||
wrap.err = errors.Wrap(err, "service build error") | ||
continue | ||
} | ||
manager.resources.AddNode(r, iface) | ||
|
@@ -501,7 +507,7 @@ func (manager *resourceManager) processRemote(ctx context.Context, | |
err = errors.New("must use Config.AllowInsecureCreds to connect to a non-TLS secured robot") | ||
} | ||
} | ||
return nil, errors.Wrapf(err, "couldn't connect to robot remote (%s)", config.Address) | ||
return nil, errors.Errorf("couldn't connect to robot remote (%s): %s", config.Address, err) | ||
} | ||
manager.logger.Debugw("connected now to remote", "remote", config.Name) | ||
return robotClient, nil | ||
|
@@ -514,7 +520,11 @@ func (manager *resourceManager) RemoteByName(name string) (robot.Robot, bool) { | |
if iface, ok := manager.resources.Node(rName); ok { | ||
part, ok := iface.(robot.Robot) | ||
if !ok { | ||
manager.logger.Errorw("tried to access remote but its not a robot interface", "remote_name", name, "type", iface) | ||
if ph, ok := iface.(*resourcePlaceholder); ok { | ||
manager.logger.Errorw("failed to get remote", "remote", name, "err", ph.err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remote not available There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
} else { | ||
manager.logger.Errorw("tried to access remote but its not a robot interface", "remote", name, "type", iface) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we going to get the relevant Type info without using %T? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't - updated |
||
} | ||
} | ||
return part, ok | ||
} | ||
|
@@ -564,6 +574,7 @@ func (manager *resourceManager) markChildrenForUpdate(ctx context.Context, rName | |
wrapper := &resourcePlaceholder{ | ||
real: nil, | ||
config: originalConfig, | ||
err: errors.New("resource marked for update"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: resource not updated yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
} | ||
manager.resources.AddNode(x, wrapper) | ||
} | ||
|
@@ -630,6 +641,7 @@ func (manager *resourceManager) wrapResource(name resource.Name, config interfac | |
wrapper = &resourcePlaceholder{ | ||
real: part, | ||
config: config, | ||
err: errors.New("resource being initialized"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: resource not initialized yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
} | ||
} | ||
// the first thing we need to do is seek if the resource name already exists as an unknownType, if so | ||
|
@@ -685,7 +697,7 @@ func (manager *resourceManager) wrapResource(name resource.Name, config interfac | |
} | ||
|
||
// updateResourceGraph using the difference between current config | ||
// and next we create resource wrappers to be consumed ny completeConfig later on | ||
// and next we create resource wrappers to be consumed by completeConfig later on | ||
// Ideally at the end of this function we should have a complete graph representation of the configuration. | ||
func (manager *resourceManager) updateResources( | ||
ctx context.Context, | ||
|
@@ -752,9 +764,11 @@ func (manager *resourceManager) updateResources( | |
func (manager *resourceManager) ResourceByName(name resource.Name) (interface{}, error) { | ||
robotPart, ok := manager.resources.Node(name) | ||
if ok && robotPart != nil { | ||
if _, ok = robotPart.(*resourcePlaceholder); !ok { | ||
ph, ok := robotPart.(*resourcePlaceholder) | ||
if !ok { | ||
return robotPart, nil | ||
} | ||
return nil, rutils.NewResourceGetError(name, ph.err) | ||
} | ||
// if we haven't found a resource of this name then we are going to look into remote resources to find it. | ||
if !ok && !name.ContainsRemoteNames() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to remove all the identifying descriptors here? I can imagine a case where these errors may be hard to debug especially if you have two components with same subtype and model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved it to https://github.com/viamrobotics/rdk/pull/1514/files#diff-77fd7ff51c1b7804c67c4df0a9a672ea0e3842b4a54bbd8ef81af82ac95c4f22R368-R369 so all errors from that function gets the additional info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh cool, Makes sense!