diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index ff115506a379..8d673dc7bef3 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -30,6 +30,7 @@ export default Ember.Component.extend(FocusOnInsertMixin, { // use a named action here so we don't have to pass one in // this will bubble to the route toggleAdvancedEdit: 'toggleAdvancedEdit', + error: null, codemirrorString: null, @@ -79,7 +80,8 @@ export default Ember.Component.extend(FocusOnInsertMixin, { 'key.isFolder', 'key.isError', 'key.flagsIsInvalid', - 'hasLintError' + 'hasLintError', + 'error' ), basicModeDisabled: computed('secretDataIsAdvanced', 'showAdvancedMode', function() { @@ -242,10 +244,15 @@ export default Ember.Component.extend(FocusOnInsertMixin, { }, codemirrorUpdated(val, codemirror) { + this.set('error', null); codemirror.performLint(); const noErrors = codemirror.state.lint.marked.length === 0; if (noErrors) { - this.get('secretData').fromJSONString(val); + try { + this.get('secretData').fromJSONString(val); + } catch (e) { + this.set('error', e.message); + } } this.set('hasLintError', !noErrors); this.set('codemirrorString', val); diff --git a/ui/app/lib/kv-object.js b/ui/app/lib/kv-object.js index 4ca3ed136c44..4c6ec8a3b959 100644 --- a/ui/app/lib/kv-object.js +++ b/ui/app/lib/kv-object.js @@ -1,13 +1,18 @@ import Ember from 'ember'; +const { typeOf, guidFor } = Ember; + export default Ember.ArrayProxy.extend({ fromJSON(json) { - const contents = Object.keys(json || []).map(key => { + if (json && typeOf(json) !== 'object') { + throw new Error('Vault expects data to be formatted as an JSON object.'); + } + let contents = Object.keys(json || []).map(key => { let obj = { name: key, value: json[key], }; - Ember.guidFor(obj); + guidFor(obj); return obj; }); this.setObjects( diff --git a/ui/app/templates/partials/secret-form-create.hbs b/ui/app/templates/partials/secret-form-create.hbs index 535e956cfc26..852e1d68321d 100644 --- a/ui/app/templates/partials/secret-form-create.hbs +++ b/ui/app/templates/partials/secret-form-create.hbs @@ -1,7 +1,7 @@