Bug 1927941 - StatusDescriptor detail item and Status component can cause runtime error when the status is an object or array
Summary: StatusDescriptor detail item and Status component can cause runtime error whe...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Management Console
Version: 4.7
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
: 4.8.0
Assignee: Jon Jackson
QA Contact: Yadan Pei
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-02-11 21:54 UTC by Jon Jackson
Modified: 2021-07-27 22:44 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Cause: OLM descriptors were not validated against the data type of the field they applied to. Consequence: A descriptor could be applied to a field with an incorrect data type, which could cause runtime errors in some cases. Fix: Update descriptor logic to validate all descriptors against the schema before attempting to render them, and log warnings for incompatible descriptors. Result: Invalid descriptors are not rendered and won't cause runtime errors or unexpected behavior.
Clone Of:
Environment:
Last Closed: 2021-07-27 22:44:18 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift console pull 8145 0 None open Bug 1927941: Fix status descriptor API and Status component edge cases 2021-02-11 22:01:43 UTC
Red Hat Product Errata RHSA-2021:2438 0 None None None 2021-07-27 22:44:35 UTC

Description Jon Jackson 2021-02-11 21:54:05 UTC
Description of problem:
When a "main" status (status descriptor with displayName "Status" or path "status") points to a value that cannot be rendered as a React child, it causes a runtime exception on the details page.

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

How reproducible:
Always

Steps to Reproduce:
1. Create resources in this gist: https://gist.github.com/TheRealJon/3680c8a573bde88a974588e269230562
2. Navigate to the details page of the MockResource instance that was just created.


Actual results:
A runtime exception occurs.

Expected results:
The edge case should be handled and the page should render normally.



Additional info:
A status descriptor with displayName "Status" or path "status" is considered the "main" status descriptor. The "main" status is the field labeled "Status" that is always rendered at the top of the details page. The data this descriptor points to is  arbitrary (we don't do any validation), and we pass it directly on to the Status component through the "status" prop. The Status component then attempts to render the status prop directly as a child of a React.Fragment. This causes an exception if the status prop is not renderable as a React.child. 
The bug surfaced because one of ACM's custom resource's "main" status descriptor points to an object, which caused an exception (Object is not a valid React child). The problem is two-fold. The Status component should handle the edge case where the status prop is not a valid React child, and the status descriptor API should also handle the case where the main status descriptor points to something other than a primitive value.

Comment 1 Jon Jackson 2021-02-25 15:53:07 UTC
Working through PR CI failures.

Comment 3 Yadan Pei 2021-03-09 03:10:21 UTC
Jon, I can still reproduce the issue following steps in `Steps to Reproduce` even on a cluster which includes fix PR

=== Cluster 4.8.0-0.nightly-2021-03-08-133419 includes fix PR
# oc get clusterversion
NAME      VERSION                             AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.8.0-0.nightly-2021-03-08-133419   True        False         3h23m   Cluster version is 4.8.0-0.nightly-2021-03-08-133419
# oc get pod console-7b7647c799-zrpn2 -n openshift-console -o yaml | grep image 
    .....
    image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:170424fa84ff1c18d4c784f8cf207414de9697696e1f88f931c0d9c3415fa716
# oc image info quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:170424fa84ff1c18d4c784f8cf207414de9697696e1f88f931c0d9c3415fa716 | grep commit
             io.openshift.build.commit.id=f4a98b081a6cded689c4b3126a59599a9a917a76
             io.openshift.build.commit.url=https://github.com/openshift/console/commit/f4a98b081a6cded689c4b3126a59599a9a917a76

# [root@preserved-qe-ui-rhel-1 console]# git log f4a98b081a6cded689c4b3126a59599a9a917a76 | grep '#8145'
    Merge pull request #8145 from TheRealJon/1927941



I can see following error:

Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=object%20with%20keys%20%7Bstatus1%2C%20status2%7D&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings. 
    $i vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861
    Ki vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861
    la vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861
    Ys vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861
    Bs vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861
    Fs vendors~main-chunk-b8279920a8a40fbe70f4.min.js:170861

Assigning back for further debugging

Comment 4 Jon Jackson 2021-03-12 17:54:14 UTC
Ah, yes. So, we changed directions a bit with this bug. Instead of handling the exception in the Status component, we let it throw, catch it in the error boundary around the descriptor component, log a warning in the console, and don't render the related item on the details page. So you will still see the exception in the browser console, but we also added a warning: "`[Invalid StatusDescriptor] Descriptor is incompatible with non-primitive value." which is the only new behavior added by this fix. This way we allow the incorrect configuration to fail as it should, and give the operator author/user more info for troubleshooting.

Comment 5 Yadan Pei 2021-03-15 07:55:46 UTC
Thank you Jon for your explanation.

Yes, I tried again and everything is working as intended. 

We can see a warning message : [Invalid StatusDescriptor] Descriptor is incompatible with non-primitive value. {description: "Invalid main status", displayName: "Status", path: "statuses"} along with the error message in browser console


Verified on 4.8.0-0.nightly-2021-03-14-134919

Comment 8 errata-xmlrpc 2021-07-27 22:44:18 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 (Moderate: OpenShift Container Platform 4.8.2 bug fix and security update), 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-2021:2438


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