RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.35k stars 1.27k forks source link

Multibody and System "there is no" exceptions should list valid values #14426

Closed ggould-tri closed 2 years ago

ggould-tri commented 3 years ago

All of the MBP by-name accessors have exceptions that say "there is no [thingy] named [mumble] in the model."

That's great and all but the only way for a user faced with this error to find out what you might have gotten wrong is to run a debug build, get a stack trace, find the enclosing call, and log the contents of the model right before the call.

The exception should list the available names to save the user from this hunt.

sherm1 commented 3 years ago

Is the proposal just to append a list of all possible [thingy]s that would not have generated an error message?

ggould-tri commented 3 years ago

That seems to me the most obvious ("you asked for 'ikea_dinera_plate_8in' but the valid models were 'ikea_dinera_plate_8in_0', 'world', 'default', ..."). But I'd be delighted with other alternatives too, so long as they don't require rebuilding in debug mode to find the failure point and add printfs.

ggould-tri commented 2 years ago

Ran into this again today with "does not have an input port named" on Diagram so I've broadened the bug description out a bit. Of course this can be addressed by the user by always including the following at each callsite but they shouldn't have to because it's silly -- it should be in the function that throws.

    drake::log()->info("ports are named: ");
    for (int i = 0; i < hub->num_input_ports(); i++) {
      drake::log()->info("{}", hub->get_input_port(i).get_name());
    }