Skip to content

Commit 54dfa9c

Browse files
author
Elias Kassell
authored
Fix catchall errors (#1802)
* Fix catchall errors on require * Bump version * Fix lint
1 parent a918c0c commit 54dfa9c

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

core/compilers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const CONTEXT_FUNCTIONS = [
1616
.map(name => `const ${name} = ctx.${name} ? ctx.${name}.bind(ctx) : undefined;`)
1717
.join("\n");
1818

19+
export const INVALID_YAML_ERROR_STRING = "is not a valid YAML file";
20+
1921
export function compile(code: string, path: string): string {
2022
if (Path.fileExtension(path) === "sqlx") {
2123
return compileSqlx(SyntaxTreeNode.create(code), path);
@@ -26,7 +28,7 @@ export function compile(code: string, path: string): string {
2628
return `exports.asJson = ${JSON.stringify(yamlAsJson)}`;
2729
} catch (e) {
2830
if (e instanceof YAMLException) {
29-
throw Error(`${path} is not a valid YAML file: ${e}`);
31+
throw new Error(`${path} ${INVALID_YAML_ERROR_STRING}: ${e}`);
3032
}
3133
throw e;
3234
}

core/workflow_settings.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { YAMLException } from "js-yaml";
2+
13
import { verifyObjectMatchesProto, VerifyProtoErrorBehaviour } from "df/common/protos";
4+
import { INVALID_YAML_ERROR_STRING } from "df/core/compilers";
25
import { version } from "df/core/version";
36
import { dataform } from "df/protos/ts";
47

@@ -77,12 +80,14 @@ function maybeRequire(file: string): any {
7780
// tslint:disable-next-line: tsr-detect-non-literal-require
7881
return nativeRequire(file);
7982
} catch (e) {
80-
if (e instanceof Error) {
81-
if (e.message.includes("Cannot find module")) {
82-
return;
83-
}
83+
if (e instanceof SyntaxError || e instanceof YAMLException) {
84+
throw e;
8485
}
85-
throw e;
86+
// The YAMLException type isn't propogated by `require`, so instead we must check the message.
87+
if (e?.message?.includes(INVALID_YAML_ERROR_STRING)) {
88+
throw e;
89+
}
90+
return undefined;
8691
}
8792
}
8893

version.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# NOTE: If you change the format of this line, you must change the bash command
22
# in /scripts/publish to extract the version string correctly.
3-
DF_VERSION = "3.0.1"
3+
DF_VERSION = "3.0.2"

0 commit comments

Comments
 (0)