Skip to content

Commit

Permalink
Fix catchall errors (#1802)
Browse files Browse the repository at this point in the history
* Fix catchall errors on require

* Bump version

* Fix lint
  • Loading branch information
Ekrekr committed Aug 8, 2024
1 parent a918c0c commit 54dfa9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion core/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
15 changes: 10 additions & 5 deletions core/workflow_settings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 54dfa9c

Please sign in to comment.