Bug 1418318 - API server gives incorrect type of error message
Summary: API server gives incorrect type of error message
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: API
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
medium
low
Target Milestone: 6.4.0
Assignee: Ondřej Pražák
QA Contact: Lukáš Hellebrandt
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-02-01 14:21 UTC by Stephen Wadeley
Modified: 2019-11-05 23:03 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-16 19:28:24 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Production Log (20.78 KB, text/plain)
2017-03-06 14:02 UTC, Stephen Wadeley
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 18892 0 None None None 2017-03-14 15:06:18 UTC

Description Stephen Wadeley 2017-02-01 14:21:13 UTC
Description of problem:

API sometimes gives Ruby error "undefined method `id' for nil:NilClass"

HTTP 500 error is more useful in this context.


Version-Release number of selected component (if applicable):

Version Satellite 6.2.6

Steps to Reproduce:

[root@rhel7-3-server  ~]# curl -H "Accept:application/json,version=2" -H  "Content-Type:application/json" -X POST -u admin:password -k -d  '{"architecture_id":"1","environment_name":"production", "domain_id":1,  "mac":"00-00-5E-00-53-00", "location_id":1, "name":"test",  "operatingsystem_id":"1","organization_id":"1"  }' https://sat6-2.example.com/api/hosts | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   247    0    68  100   179    574   1513 --:--:-- --:--:-- --:--:--  1516
{
    "error": {
        "message": "undefined method `id' for nil:NilClass"
    }
}

Actual results:

"error": {
        "message": "undefined method `id' for nil:NilClass"

Expected results:

HTTP 500 Internal Error

Additional info:

Comment 3 Marek Hulan 2017-02-21 09:35:35 UTC
Hello Stephen, could you please also upload the production.log from time when you run this API call? This is generic error message which happens if there's bug in code so I'd like to know what was the cause. Anyway I agree we should print nicer error suggesting to look at production.log maybe.

Comment 4 Stephen Wadeley 2017-03-06 14:02:17 UTC
Created attachment 1260413 [details]
Production Log

Hello

I am sorry for delay. I could not find log from that long ago but managed to reproduce it. Here is new log.

I ran the command directly in the Satellite VM, not a remote VM, hope that is OK.

Comment 5 Ondřej Pražák 2017-03-14 15:06:15 UTC
Created redmine issue http://projects.theforeman.org/issues/18892 from this bug

Comment 6 Satellite Program 2017-03-14 16:09:47 UTC
Upstream bug assigned to oprazak

Comment 7 Satellite Program 2017-03-14 16:09:51 UTC
Upstream bug assigned to oprazak

Comment 10 Marek Hulan 2017-06-15 11:18:03 UTC
For the record, the original issue has been fixed by https://bugzilla.redhat.com/show_bug.cgi?id=1379006, the message now would look like following

{"message":"Location with id 1 not found"}

In your example you used the same id for location and organization which is obviously wrong.

As a fix for this BZ, Ondra worked on a patch so that the message is different if similar issue happened again.

Comment 11 Marek Hulan 2017-06-30 11:30:58 UTC
Ondra's PR mentioned in comment 10 was merged in upstream. It's scheduled to be part of 1.16.

Comment 12 Satellite Program 2017-06-30 12:10:21 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/18892 has been resolved.

Comment 13 Lukáš Hellebrandt 2018-06-25 14:05:26 UTC
I understand this BZ as "when there is ISE, API call should actually return 500 ISE". So I tried to cause ISE in the similar place as in the original traceback, adding "dummy = values_for_primary_interface.id" to 'def initialize' block after 'values_for_primary_interface = {}' in /usr/share/foreman/app/models/host/base.rb. Then:

# curl -v -H "Accept:application/json,version=2" -H  "Content-Type:application/json" -X POST -u admin:password -k https://$(hostname)/api/hosts
[...]
< Status: 500 Internal Server Error
[...]
{
  "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."}
}

Status is 500 ISE, error message is on output -> verified with Sat 6.4 snap 8.

Comment 14 Bryan Kearney 2018-10-16 19:28:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927


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