Skip to content
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

RDSK-9311: (gripper/input-controller) Guard against nil responses in rdk client/servers #4620

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

martha-johnston
Copy link
Contributor

@martha-johnston martha-johnston commented Dec 11, 2024

went through encoder, gripper, input controller, motor, and posetracker server code to see what had the possibility to be returned as nil, and added checks to return errors in that case. also added tests for each nil failure. there were no changes for encoder, motor, or pose tracker.

added necessary tests to client test file to ensure that the server changes resulted in the same returned error, so the checks didn't need to be added in the client files as well.

still need to do this for the other components, but want to break up the work into smaller PRs (#4618 & #4621)

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Dec 11, 2024
@martha-johnston martha-johnston changed the title RDSK-9311: (gripper/input-controller/motor) Guard against nil responses in rdk client/servers RDSK-9311: (gripper/input-controller/) Guard against nil responses in rdk client/servers Dec 11, 2024
@martha-johnston martha-johnston changed the title RDSK-9311: (gripper/input-controller/) Guard against nil responses in rdk client/servers RDSK-9311: (gripper/input-controller) Guard against nil responses in rdk client/servers Dec 11, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 11, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 11, 2024
@martha-johnston martha-johnston requested review from a team and oliviamiller and removed request for a team December 11, 2024 22:08
@martha-johnston martha-johnston marked this pull request as ready for review December 11, 2024 22:08
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 12, 2024
@@ -145,6 +148,9 @@ func TestClient(t *testing.T) {
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldContainSubstring, errStopUnimplemented.Error())

_, err = client2.Geometries(context.Background(), extra)
test.That(t, err.Error(), test.ShouldContainSubstring, gripper.ErrGeometriesNil(failGripperName).Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldErrors.Is work here? I think we are trying to avoid using substring for errors test when possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that it adds "rpc error: code = Unknown desc = " before the actual error, so figured it was easier to use substring. in the server code it doesn't add that string, so you can just use test.ShouldBeError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although I guess I didn't try Errors.Is perhaps that's easier, I've never seen that in the test.That() format, I'll try it out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense thanks for explaining! I meant test.ShouldBeError so prob fine to leave as is


_, err = client2.Events(context.Background(), map[string]interface{}{})
test.That(t, err, test.ShouldNotBeNil)
test.That(t, err.Error(), test.ShouldContainSubstring, errEventsFailed.Error())
test.That(t, err.Error(), test.ShouldContainSubstring, input.ErrEventsNil(failInputControllerName).Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still be testing the previous errors or is it not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not needed because errControlsFailed is just an error that was defined in this package and was only returned from the injected input controller. now we are testing if the real function returns the expected error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants