From 60dd24502dc1e71b28cdeb3723226fde66e48dc1 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 17 Mar 2020 13:52:17 -0700 Subject: [PATCH] Better account for invalid yaml parsing --- .../services/datasource_to_agent_datasource.test.ts | 4 ++++ .../common/services/datasource_to_agent_datasource.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.test.ts b/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.test.ts index c753f25c0cb3ff..7b4e4adc4e4fc2 100644 --- a/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.test.ts +++ b/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.test.ts @@ -43,6 +43,10 @@ describe('Ingest Manager - storedDatasourceToAgentDatasource', () => { type: 'yaml', value: '', }, + barVar5: { + type: 'yaml', + value: 'testField: test\n invalidSpacing: foo', + }, }, }, ], diff --git a/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.ts b/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.ts index d5bedcf4c1b980..ea048b84afef33 100644 --- a/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.ts +++ b/x-pack/plugins/ingest_manager/common/services/datasource_to_agent_datasource.ts @@ -28,8 +28,13 @@ export const storedDatasourceToAgentDatasource = ( (acc, [configName, { type: configType, value: configValue }]) => { if (configValue !== undefined) { if (configType === 'yaml') { - if (configValue.trim()) { - acc[configName] = safeLoad(configValue); + try { + const yamlValue = safeLoad(configValue); + if (yamlValue) { + acc[configName] = yamlValue; + } + } catch (e) { + // Silently swallow parsing error } } else { acc[configName] = configValue;