Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1786182 - [RFE] Improve handling of template rendering failures and reporting of errors.
Summary: [RFE] Improve handling of template rendering failures and reporting of errors.
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Provisioning Templates
Version: 6.6.0
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Ondrej Gajdusek
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-12-23 18:15 UTC by Dylan Gross
Modified: 2023-09-07 21:20 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-08-10 21:37:00 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 29204 0 Normal New Improve handling of template rendering failures and reporting of errors. 2020-09-30 15:05:13 UTC

Description Dylan Gross 2019-12-23 18:15:17 UTC
1. Proposed title of this feature request

    Improve handling of template rendering failures and reporting of errors.
 
3. What is the nature and description of the request?

    When a template fails to render, it returns a vague error in the UI saying:
           
      "We're sorry, but something went wrong.
       If you are the application owner check the logs for more information."

    This does not give the impression that it's necessarily a template rendering error (as the page is devoid of any of the Satellite UI components, but appears to be just a 500 Internal Server Error).   This suggests to the user there could be larger internal satellite issues at hand.

4. Why does the customer need this? (List the business requirements here)

    Satellite users who have ability to manage hosts and templates do not always have access to the Satellite's system's logs.   If the UI user is told that the problem is a template rendering error (and perhaps where the error occurs) it would simplify troubleshooting

5. How would the customer like to achieve this? (List the functional requirements here)

    Ideally the error could be caught and displayed within the Satellite WebUI so that the user doesn't think it's just some httpd or other issue.   Also, if the nature of the error and a line number of where the error occurred in the template, that would be useful

6. For each functional requirement listed, specify how Red Hat and the customer can test to confirm the requirement is successfully implemented.

   Cause a template to fail to render.  Be able to discern from the error in the WebUI that it is a template rendering error, and what part of the template had the issue.

7. Is there already an existing RFE upstream or in Red Hat Bugzilla?

   No.

   (While Bug 1776515 - "[RFE] Improve Reporting and Kickstarts Templates editing" initially seemed similar from the title, it was asking for was the creation of a form or tool to abstract the creation of templates. )

8. Does the customer have any specific timeline dependencies and which release would they like to target (i.e. RHEL5, RHEL6)?

   No

9. Is the sales team involved in this request and do they have any additional input?

   No.

10. List any affected packages or components.

   Red Hat Satellite 6.6

11. Would the customer be able to assist in testing this functionality if implemented?

   Yes.

Comment 4 Dylan Gross 2019-12-23 18:28:53 UTC
I generate a failure by adding a non-existent snippet to the middle of a provisioning template and then trying to "review" the template for an applicable host.

  <%= snippet "non-existent snippet" %>

   --- or even some gibberish ---

  <%= (%>

While the production.log (below) technically gives me details about what was wrong, it is not always accessible to the same users and can still be rather generic.


2019-12-23T12:53:28 [I|app|0525e2ad] Started GET "/unattended/provision?hostname=myhost.example.com" for 192.168.x.x at 2019-12-23 12:53:28 -0500
2019-12-23T12:53:28 [I|app|0525e2ad] Processing by UnattendedController#host_template as TEXT
2019-12-23T12:53:28 [I|app|0525e2ad]   Parameters: {"hostname"=>"myhost.example.com", "kind"=>"provision"}
2019-12-23T12:53:28 [I|app|0525e2ad] Current user set to admin (admin)
2019-12-23T12:53:28 [W|app|0525e2ad] Error rendering the AA_Kickstart_RHEL8 template
2019-12-23T12:53:28 [W|app|0525e2ad] Action failed
2019-12-23T12:53:28 [I|app|0525e2ad] Completed 500 Internal Server Error in 209ms (ActiveRecord: 17.6ms)
2019-12-23T12:53:28 [F|app|0525e2ad]   
2019-12-23T12:53:28 [F|app|0525e2ad] ActionView::MissingTemplate (Missing template common/500 with {:locale=>[:en], :formats=>[:text], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :rabl]}. Searched in:
  * "/usr/share/foreman/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_inventory_upload-1.0.2/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-3.0.7.1/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_virt_who_configure-0.4.4/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.8.0.4/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_openscap-1.0.8/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_theme_satellite-4.0.1.7/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_bootdisk-15.0.0/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/redhat_access-2.2.8/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/engines/bastion/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.15.11.1/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_discovery-15.0.2/app/views"
  * "/opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/app/views"
):
2019-12-23T12:53:28 [F|app|0525e2ad]   
2019-12-23T12:53:28 [F|app|0525e2ad] app/controllers/application_controller.rb:325:in `generic_exception'
lib/foreman/middleware/telemetry.rb:10:in `call'
lib/foreman/middleware/catch_json_parse_errors.rb:9:in `call'
lib/foreman/middleware/logging_context_session.rb:22:in `call'
lib/foreman/middleware/logging_context_request.rb:11:in `call'
katello (3.12.0.29) lib/katello/prevent_json_parsing.rb:12:in `call'

Comment 7 Marek Hulan 2020-01-20 17:05:23 UTC
There are few things to mention here. We can't reliably predict, whether the template will render correctly or not. For obvious errors like syntax errors or missing snippets, that's easy, but for code that is in if-condition, that only gets entered during provisioning, we can't tell. When user provisions the host, we validate the templates by rendering and let user know if the template can't be rendered. But it can change while the host boot obviously. We also can't tell user which line contains the error, because we only know line numbers once ERB tags are compiled. I think line numbers only work if safe mode is disabled.

However I agree we should render different error than 500 if the template rendering fails. Something like 503 would be more appropriate. So, I take it as the request in this BZ. We'll also look if we can improve the message on such error page. At least printing some info with request ID to follow up with person who has access to logs would be good. As stated above, it's not possible to reliably say, what line causes the issue. Last but not least, some errors (not all) may be caught by ERB syntax checker. E.g. unclosed ERB tags. That is also something that can be added.

Comment 8 Leos Stejskal 2020-02-27 09:22:36 UTC
Created redmine issue https://projects.theforeman.org/issues/29204 from this bug

Comment 9 Leos Stejskal 2020-02-27 11:58:17 UTC
Hi,
I couldn't reproduce your issue, every time I've got correct error message about the problem.

My steps:
0) Run foreman as "RAILS_ENV=production bundle exec foreman start" (latest develop branch)
1) Created template with "<%= (%>" & GET /unattended/provision?hostname=host.ex.com
Error is displayed: "There was an error rendering the AAA_KICK_PROVISION template: ERF22-6132 [Foreman::Renderer::Errors::SyntaxError]: Syntax error occurred while parsing the template AAA_KICK_PROVISION, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):2 :: parse error on value ";" (tSEMI)"
2) Created template with <%= snippet "non-existent snippet" %> & GET /unattended/provision?hostname=host.ex.com
Error: There was an error rendering the AAA_KICK_PROVISION template: The specified snippet 'non-existent snippet' does not exist, or is not a snippet.

When I checked the application code[1], we are catching StandardError class and returning the error message in response.

Can you please check if you can still reproduce the issue?
Thanks.

[1] https://github.com/theforeman/foreman/blob/f75b27377e82fd9760a67764b64cbc17d66ef3c9/app/controllers/concerns/foreman/controller/template_rendering.rb#L17

Comment 10 Marek Hulan 2020-02-28 11:35:05 UTC
I see that in the reproducing steps, the format was "text" but it seems you're reproducing with curl which probably deafults to html. Try GET /unattended/provision?hostname=host.ex.com&format=text (or txt) and you'll see we don't have templates for 500 for plain text format, which masks the original error.

Also the question is, what error code we should use in the case that template contains syntax error. I'd consider 503, the template may be fixed later.

Comment 11 Leos Stejskal 2020-02-28 12:21:42 UTC
I found the way how to reproduce it, my fault. It wasn't problem with missing format, but with that I was signed in as admin, therefore I've got different behavior. 
So the issue is reproducible and I'm looking into it right now.

Comment 12 Leos Stejskal 2020-03-03 11:17:13 UTC
Hi,
after some investigation I found that the issue has been fixed in Satellite 6.7 (foreman 1.24), here is the link to PR: https://github.com/theforeman/foreman/pull/6057

Comment 14 Leos Stejskal 2020-03-03 14:27:38 UTC
Current behavior on Satellite 6.7:

When there is error during rendering template, proper error message is displayed instead of just generic "500 Something went wrong ...".

Examples:

Template with "<%= (%>" will get error:
  There was an error rendering the AAA_KICK_PROVISION template: ERF22-6132 [Foreman::Renderer::Errors::SyntaxError]: Syntax error occurred while parsing the template AAA_KICK_PROVISION, make sure you have all 
  ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):2 :: parse error on value ";" (tSEMI)

Template with <%= snippet "non-existent snippet" %> will get error:
  There was an error rendering the AAA_KICK_PROVISION template: The specified snippet 'non-existent snippet' does not exist, or is not a snippet.

Steps to verify:
- Login as admin
- Edit provisioning template, set template to "<%= (%>"
- Go to host detail > Templates > Provisioning template > Review

Correct error message is displayed.

Dylan can you please verify the fix and close the issue if everything is okay?
Thank you

Comment 19 Mike McCune 2021-07-13 21:54:48 UTC
Upon review of our valid but aging backlog the Satellite Team has concluded that this Bugzilla does not meet the criteria for a resolution in the near term, and are planning to close in a month. This message may be a repeat of a previous update and the bug is again being considered to be closed. If you have any concerns about this, please contact your Red Hat Account team.  Thank you.

Comment 20 Mike McCune 2021-08-10 21:34:00 UTC
Thank you for your interest in Red Hat Satellite. We have evaluated this request, and while we recognize that it is a valid request, we do not expect this to be implemented in the product in the foreseeable future. This is due to other priorities for the product, and not a reflection on the request itself. We are therefore closing this out as WONTFIX. If you have any concerns about this feel free to contact your Red Hat Account Team. Thank you.


Note You need to log in before you can comment on or make changes to this bug.