Skip to content

Commit

Permalink
Merge pull request #3630 from spadgett/yaml-sample-error-handling
Browse files Browse the repository at this point in the history
Bug 1776479: Show error modal for invalid YAML samples
  • Loading branch information
openshift-merge-robot committed Dec 4, 2019
2 parents 87c9e3e + d46bfd0 commit c790bfc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions frontend/public/components/edit-yaml.jsx
Expand Up @@ -15,6 +15,7 @@ import {
import { getBadgeFromType, Shortcut, ShortcutTable } from '@console/shared';

import { connectToFlags } from '../reducers/features';
import { errorModal } from './modals';
import { Firehose, checkAccess, history, Loading, resourceObjPath } from './utils';
import { FLAGS, ALL_NAMESPACES_KEY } from '../const';
import {
Expand Down Expand Up @@ -446,9 +447,16 @@ const EditYAML_ = connect(stateToProps)(
}

getYamlContent_(id = 'default', yaml = '', kind = referenceForModel(this.props.model)) {
const sampleObj = generateObjToLoad(kind, id, yaml, this.props.obj.metadata.namespace);
this.setState({ sampleObj });
return sampleObj;
try {
const sampleObj = generateObjToLoad(kind, id, yaml, this.props.obj.metadata.namespace);
this.setState({ sampleObj });
return sampleObj;
} catch ({ message, name }) {
errorModal({
title: 'Failed to Parse YAML Sample',
error: <div className="co-pre-line">{message || name || 'An error occurred.'}</div>,
});
}
}

insertYamlContent_ = (id, yaml, kind) => {
Expand All @@ -462,9 +470,13 @@ const EditYAML_ = connect(stateToProps)(
};

downloadSampleYaml_(id = 'default', yaml = '', kind = referenceForModel(this.props.model)) {
const sampleObj = generateObjToLoad(kind, id, yaml, this.props.obj.metadata.namespace);
const data = safeDump(sampleObj);
this.download(data);
try {
const sampleObj = generateObjToLoad(kind, id, yaml, this.props.obj.metadata.namespace);
const data = safeDump(sampleObj);
this.download(data);
} catch (e) {
this.download(yaml);
}
}

registerYAMLinMonaco(monaco) {
Expand Down

0 comments on commit c790bfc

Please sign in to comment.