Skip to content

Commit

Permalink
Correctly report filenames in compilation Errors created in compile(…
Browse files Browse the repository at this point in the history
…). (#350)

* Correctly report filenames in compilation Errors created in compile().

* fixes
  • Loading branch information
BenBirt authored Aug 8, 2019
1 parent eb1d1f8 commit 58a5226
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
3 changes: 2 additions & 1 deletion core/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export class Operation {
this.session.compileError(
new Error(
"Actions of type 'operations' may only describe columns if they specify 'hasOutput: true'."
)
),
this.proto.fileName
);
}

Expand Down
13 changes: 10 additions & 3 deletions core/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,21 @@ export class Test {
public compile() {
const testContext = new TestContext(this);
if (!this.datasetToTest) {
this.session.compileError(new Error("Tests must operate upon a specified dataset."));
this.session.compileError(
new Error("Tests must operate upon a specified dataset."),
this.proto.fileName
);
} else {
const dataset = this.session.tables[this.datasetToTest];
if (!dataset) {
this.session.compileError(new Error(`Dataset ${this.datasetToTest} could not be found.`));
this.session.compileError(
new Error(`Dataset ${this.datasetToTest} could not be found.`),
this.proto.fileName
);
} else if (dataset.proto.type === "incremental") {
this.session.compileError(
new Error("Running tests on incremental datasets is not yet supported.")
new Error("Running tests on incremental datasets is not yet supported."),
this.proto.fileName
);
} else {
const refReplacingContext = new RefReplacingContext(testContext);
Expand Down
55 changes: 28 additions & 27 deletions core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,37 @@ export function matchPatterns(patterns: string[], values: string[]) {
}

export function getCallerFile(rootDir: string) {
const originalFunc = Error.prepareStackTrace;
let callerfile;
let lastfile;
let lastfile: string;
const stack = getCurrentStack();
while (stack.length) {
lastfile = stack.shift().getFileName();
if (!lastfile) {
continue;
}
if (!lastfile.includes(rootDir)) {
continue;
}
if (lastfile.includes("node_modules")) {
continue;
}
if (!(lastfile.includes("definitions/") || lastfile.includes("models/"))) {
continue;
}
break;
}
return relativePath(lastfile, rootDir);
}

function getCurrentStack(): NodeJS.CallSite[] {
const originalPrepareStackTrace = Error.prepareStackTrace;
try {
const err = new Error();
let currentfile;
Error.prepareStackTrace = function(err, stack) {
Error.prepareStackTrace = (err, stack) => {
return stack;
};

currentfile = (err.stack as any).shift().getFileName();
while (err.stack.length) {
callerfile = (err.stack as any).shift().getFileName();
if (callerfile) {
lastfile = callerfile;
}
if (
currentfile !== callerfile &&
callerfile.includes(rootDir) &&
!callerfile.includes("node_modules") &&
// We don't want to attribute files in includes/ to the caller files.
(callerfile.includes("definitions/") || callerfile.includes("models/"))
) {
break;
}
}
} catch (e) {}
Error.prepareStackTrace = originalFunc;

return relativePath(callerfile || lastfile, rootDir);
return (new Error().stack as unknown) as NodeJS.CallSite[];
} finally {
Error.prepareStackTrace = originalPrepareStackTrace;
}
}

export function graphHasErrors(graph: dataform.ICompiledGraph) {
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 = "1.1.1"
DF_VERSION = "1.1.2"

0 comments on commit 58a5226

Please sign in to comment.