diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 42beb2c44..8a5c04a00 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -644,6 +644,15 @@ describe "Config", -> nestedObject: nestedBool: true + it 'will set only the values that adhere to the schema', -> + expect(atom.config.set 'foo.bar', + anInt: 'nope' + nestedObject: + nestedBool: true + ).toBe true + expect(atom.config.get('foo.bar.anInt')).toEqual 12 + expect(atom.config.get('foo.bar.nestedObject.nestedBool')).toEqual true + describe 'when the value has an "array" type', -> beforeEach -> schema = diff --git a/src/config.coffee b/src/config.coffee index 14c4c817b..b82fce05e 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -404,16 +404,27 @@ Config.addSchemaValidators coercion: (value, schema) -> throw new Error('Value must be an object') if typeof value isnt 'object' return value unless schema.properties? + newValue = {} for prop, childSchema of schema.properties - value[prop] = @executeSchemaValidators(value[prop], childSchema) if prop of value - value + continue unless prop of value + try + newValue[prop] = @executeSchemaValidators(value[prop], childSchema) + catch error + ; + newValue 'array': coercion: (value, schema) -> throw new Error('Value must be an array') unless Array.isArray(value) itemSchema = schema.items if itemSchema? - @executeSchemaValidators(item, itemSchema) for item in value + newValue = [] + for item in value + try + newValue.push @executeSchemaValidators(item, itemSchema) + catch error + ; + newValue else value