Hammer(1) technically correct error messages

Problem: I have been exploring hammer(1) and got an error message, which I understood quite quickly, but that was not obvious - especially in the more likely case, which I will also demonstrate here.

Expected outcome: An error which might give context to the technically correct information contained within it (see the second example in particular, which is without any context).

Foreman and Proxy versions: Foreman 2.1 (EL8 repo)

Foreman and Proxy plugin versions:

hammer --version
hammer (2.1.1)
 * hammer_cli_foreman (2.1.1)
 * hammer_cli_foreman_ansible (0.3.2)
 * hammer_cli_foreman_discovery (1.0.2)
 * hammer_cli_foreman_remote_execution (unknown version)
 * hammer_cli_foreman_tasks (unknown version)

Aside: (unknown version) :frowning:

Distribution and version: CentOS 8.2

Other relevant data:

The command line executed in these examples (redacted):

hammer os create \
    --name                'CentOS' \
    --organization-title  'My Default Organization Name' \
    --location-title      'My Default Location' \
    --location-title      'My Backup Location' \
    --major               '8' \
    --minor               '2.2004' \
    --family              'Redhat' \
    --architectures       'x86_64' \
    --media               'CentOS 8 mirror'

The exit status was 65. The error message was:

Could not create the operating system:
  Couldn't find Medium with 'id'=[2] [WHERE (media.id IN (12,13))]

Thankfully, that was actually useful, as I quickly realized, that media.id of 12 and 13 belonged to media I had created, and importantly associated with my backup site. So I looked at media.id 2 and sure enough, it was only associated with my primary site. So that was easy enough to fix (in my case in the WebUI to speed things along) and the command than worked successfully.

So the reason for the post, is to actually highlight the default case, when you have not defined your own media, which would be common to a lot of new users, as Foreman has a reasonable initial media set. So I removed the backup site access to the media in question, restoring it to the default configuration. I also removed my now successfully created ‘os’ entry, and the two medium entities that I created, and tried again, and got the extremely helpful:

Could not create the operating system:
  Couldn't find Medium with 'id'=[2] [WHERE (1=0)]

Well, obviously it could find the medium with id=2 (as it has an id and is not reporting the text I provided on the command line), but the SQL WHERE clause is now not at all enlightening! Could I suggest that something along the lines of the following for all errors that fail organization and location, or any similar access checks:

Could not create the operating system:
  The requested Medium <<mediumTitle>> id=<<mediumId>> is not available at the requested Organization or Location.

or more generally, on the assumption that access checks are primarily Organization and Location:

Could not create the <<OneEntityType>>:
  The requested <<EntityType>> <<entityTitleOrName>> id=<<EntityId>> is not available at the requested organization or location.

Obviously, if the code that created the message has access to more information that would be ideal. But even if the above had to be generalized as it could be more than Organization or Location, a simple “requested organization, location, …” would still give the user a clue of what went wrong, especially in the generic case.

Reported under the notion that “if you see something, you should say something”

Regards,
Peter

2 Likes