From 54dfa9ce51b141124608f0b5e15fa01f714e093a Mon Sep 17 00:00:00 2001 From: Elias Kassell Date: Thu, 8 Aug 2024 16:53:42 +0100 Subject: [PATCH] Fix catchall errors (#1802) * Fix catchall errors on require * Bump version * Fix lint --- core/compilers.ts | 4 +++- core/workflow_settings.ts | 15 ++++++++++----- version.bzl | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/compilers.ts b/core/compilers.ts index 5f3a06113..fc6b23817 100644 --- a/core/compilers.ts +++ b/core/compilers.ts @@ -16,6 +16,8 @@ const CONTEXT_FUNCTIONS = [ .map(name => `const ${name} = ctx.${name} ? ctx.${name}.bind(ctx) : undefined;`) .join("\n"); +export const INVALID_YAML_ERROR_STRING = "is not a valid YAML file"; + export function compile(code: string, path: string): string { if (Path.fileExtension(path) === "sqlx") { return compileSqlx(SyntaxTreeNode.create(code), path); @@ -26,7 +28,7 @@ export function compile(code: string, path: string): string { return `exports.asJson = ${JSON.stringify(yamlAsJson)}`; } catch (e) { if (e instanceof YAMLException) { - throw Error(`${path} is not a valid YAML file: ${e}`); + throw new Error(`${path} ${INVALID_YAML_ERROR_STRING}: ${e}`); } throw e; } diff --git a/core/workflow_settings.ts b/core/workflow_settings.ts index 3aa83835c..f93fd0b28 100644 --- a/core/workflow_settings.ts +++ b/core/workflow_settings.ts @@ -1,4 +1,7 @@ +import { YAMLException } from "js-yaml"; + import { verifyObjectMatchesProto, VerifyProtoErrorBehaviour } from "df/common/protos"; +import { INVALID_YAML_ERROR_STRING } from "df/core/compilers"; import { version } from "df/core/version"; import { dataform } from "df/protos/ts"; @@ -77,12 +80,14 @@ function maybeRequire(file: string): any { // tslint:disable-next-line: tsr-detect-non-literal-require return nativeRequire(file); } catch (e) { - if (e instanceof Error) { - if (e.message.includes("Cannot find module")) { - return; - } + if (e instanceof SyntaxError || e instanceof YAMLException) { + throw e; } - throw e; + // The YAMLException type isn't propogated by `require`, so instead we must check the message. + if (e?.message?.includes(INVALID_YAML_ERROR_STRING)) { + throw e; + } + return undefined; } } diff --git a/version.bzl b/version.bzl index 4f52c73c2..04b5e105f 100644 --- a/version.bzl +++ b/version.bzl @@ -1,3 +1,3 @@ # NOTE: If you change the format of this line, you must change the bash command # in /scripts/publish to extract the version string correctly. -DF_VERSION = "3.0.1" +DF_VERSION = "3.0.2"