From 63eff7db2d2e277d26a5d6c51dc491d24a59144f Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Thu, 14 Dec 2023 15:34:32 +0100 Subject: [PATCH] fix(cli): fallback to non-highlighted yaml if error occurs (#5560) This is a quickfix for #5442 to avoid Garden crashes on yaml highlighting. The proper fix still needs to be implemented. --- core/src/util/serialization.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/util/serialization.ts b/core/src/util/serialization.ts index d06cd5c98a..3a2d1c690f 100644 --- a/core/src/util/serialization.ts +++ b/core/src/util/serialization.ts @@ -35,14 +35,21 @@ export function encodeYamlMulti(objects: object[]) { } export function highlightYaml(s: string) { - return highlight(s, { - language: "yaml", - theme: { - keyword: styles.accent.italic, - literal: styles.accent.italic, - string: styles.accent, - }, - }) + try { + return highlight(s, { + language: "yaml", + theme: { + keyword: styles.accent.italic, + literal: styles.accent.italic, + string: styles.accent, + }, + }) + } catch (err) { + // FIXME: this is a quickfix for https://github.com/garden-io/garden/issues/5442 + // The issue needs to be fixed properly, by fixing Garden single app binary construction. + // Fallback to non-highlighted yaml if an error occurs. + return s + } } /**