Skip to content

Fixes #39372 - Extract displayMessage from validation errors#655

Open
chris1984 wants to merge 1 commit into
theforeman:masterfrom
chris1984:update-exceptionhandler
Open

Fixes #39372 - Extract displayMessage from validation errors#655
chris1984 wants to merge 1 commit into
theforeman:masterfrom
chris1984:update-exceptionhandler

Conversation

@chris1984
Copy link
Copy Markdown
Member

@chris1984 chris1984 commented May 28, 2026

When the Foreman/Katello API returns validation errors (422 status), it includes detailed error messages in the 'displayMessage' field. The exception handler was only checking 'message' and 'full_messages', causing detailed error information to be lost.

This commit updates handle_unprocessable_entity to check for 'displayMessage' first, matching the behavior of handle_foreman_error which already handles this field correctly.

Before:
Could not update the host

After:
Could not update the host:
Validation failed: Host example.com: Cannot add content view
environment to content facet. The host's content source does
not sync lifecycle environment 'Library'.

Before patch:

hammer -d host update --id 3 --content-view-environments Library/Zoo
Could not update the host.

After patch:

hammer host update --id 3 --content-view-environments Library/Zoo
Could not update the host:
Validation failed: Host host.example.com: Cannot add content view environment to content facet. The host's content source 'capsule.example.com' does not sync lifecycle environment 'Library'.

Testing Steps:

  1. Create multiple Content Views (e.g., cv_1 & cv_2) and multiple Lifecycle Environments (e.g., 'Library' and 'Dev').

  2. Publish new versions of all Content Views and promote them to the 'Dev' lifecycle environment.

  3. Add only the 'Dev' lifecycle environment to the external Capsule, ensuring that the 'Library' lifecycle environment is not added. Then, synchronize the Capsule server.

  4. Register the client to the Capsule server.

  5. Try to update the hosts content view environments to one not synced on the capsule
    hammer -d host update --id 3 --content-view-environments Library/Zoo

  6. Verify you see the real error and not the generic can't update host error

Comment thread lib/hammer_cli_foreman/exception_handler.rb Outdated
When the Foreman/Katello API returns validation errors (422 status),
it includes detailed error messages in the 'displayMessage' field.
The exception handler was only checking 'message' and 'full_messages',
causing detailed error information to be lost.

This commit updates handle_unprocessable_entity to check for
'displayMessage' first, matching the behavior of handle_foreman_error
which already handles this field correctly.

Before:
  Could not update the host

After:
  Could not update the host:
    Validation failed: Host example.com: Cannot add content view
    environment to content facet. The host's content source does
    not sync lifecycle environment 'Library'.
@chris1984 chris1984 force-pushed the update-exceptionhandler branch from 47926d4 to 2eb4b14 Compare May 29, 2026 18:14
response = JSON.parse(e.response)
response = HammerCLIForeman.record_to_common_format(response) unless response.has_key?('message')
print_error response['message'] || response['full_messages']
print_error response['message'] || response['full_messages'] || response['displayMessage']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is displayMessage purely a Katello-ism? We are on the 5.0 release cycle; if Katello can align its API with the expectations already here, that'd be a win IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants