Skip to content

Commit

Permalink
Ensure that parse errors have the appropriate relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Dec 6, 2022
1 parent f07c964 commit cc97c47
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<Binary> parseInputs(Iterable<Input> sources, @Nullable Path relative
null,
readAllBytes(source.getSource(ctx))));
} catch (Exception e) {
ParsingExecutionContextView.view(ctx).parseFailure(source, this, e);
ParsingExecutionContextView.view(ctx).parseFailure(source, relativeTo, this, e);
ctx.getOnError().accept(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public List<PlainText> parseInputs(Iterable<Input> sources, @Nullable Path relat
plainTexts.add(plainText);
parsingListener.parsed(source, plainText);
} catch (Throwable t) {
ParsingExecutionContextView.view(ctx).parseFailure(source, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(source, relativeTo, this, t);
ctx.getOnError().accept(t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public ParsingEventListener getParsingListener() {
return getMessage(PARSING_LISTENER, ParsingEventListener.NOOP);
}

public ParsingExecutionContextView parseFailure(Parser.Input input, Parser<?> parser, Throwable t) {
PlainText pt = new PlainText(randomId(), input.getPath(), Markers.EMPTY, null, false,
public ParsingExecutionContextView parseFailure(Parser.Input input, @Nullable Path relativeTo, Parser<?> parser, Throwable t) {
PlainText pt = new PlainText(randomId(), input.getRelativePath(relativeTo), Markers.EMPTY, null, false,
null, null, input.getSource(this).readFully());
return parseFailure(pt, parser, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public List<G.CompilationUnit> parseInputs(Iterable<Input> sources, @Nullable Pa
cus.add(gcu);
parsingListener.parsed(compiled.getInput(), gcu);
} catch (Throwable t) {
pctx.parseFailure(compiled.getInput(), this, t);
pctx.parseFailure(compiled.getInput(), relativeTo, this, t);
ctx.getOnError().accept(t);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ List<CompiledGroovySource> parseInputsToCompilerAst(Iterable<Input> sources, @Nu

cus.add(new CompiledGroovySource(input, unit, ast));
} catch (Throwable t) {
ctx.parseFailure(input, this, t);
ctx.parseFailure(input, relativeTo, this, t);
ctx.getOnError().accept(t);
} finally {
if (logCompilationWarningsAndErrors && (errorCollector.hasErrors() || errorCollector.hasWarnings())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public List<Hcl.ConfigFile> parseInputs(Iterable<Input> sourceFiles, @Nullable P
return configFile;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(t);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public List<J.CompilationUnit> parseInputs(Iterable<Input> sourceFiles, @Nullabl
.tag("file.type", "Java")
.tag("step", "(3) Map to Rewrite AST"), t)
.register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(input, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(input, relativeTo, this, t);
ctx.getOnError().accept(t);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public List<J.CompilationUnit> parseInputs(Iterable<Input> sourceFiles, @Nullabl
.tag("file.type", "Java")
.tag("step", "(3) Map to Rewrite AST"), t)
.register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(input, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(input, relativeTo, this, t);
ctx.getOnError().accept(t);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public List<J.CompilationUnit> parseInputs(Iterable<Input> sourceFiles, @Nullabl
.tag("file.type", "Java")
.tag("step", "(3) Map to Rewrite AST"), t)
.register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(input, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(input, relativeTo, this, t);
ctx.getOnError().accept(t);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<Json.Document> parseInputs(Iterable<Input> sourceFiles, @Nullable Pa
return document;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(new IllegalStateException(sourceFile.getPath() + " " + t.getMessage(), t));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public List<Xml.Document> parseInputs(Iterable<Input> sources, @Nullable Path re
projectPoms.put(xml, pom);
projectPomsByPath.put(pomPath, pom);
} catch (Throwable t) {
ParsingExecutionContextView.view(ctx).parseFailure(source, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(source, relativeTo, this, t);
ctx.getOnError().accept(t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public List<Properties.File> parseInputs(Iterable<Input> sourceFiles, @Nullable
return file;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(new IllegalStateException(sourceFile.getPath() + " " + t.getMessage(), t));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<Proto.Document> parseInputs(Iterable<Input> sourceFiles, @Nullable P
return document;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(new IllegalStateException(path + " " + t.getMessage(), t));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public List<Xml.Document> parseInputs(Iterable<Input> sourceFiles, @Nullable Pat
return document;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(new IllegalStateException(path + " " + t.getMessage(), t));
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<Yaml.Documents> parseInputs(Iterable<Input> sourceFiles, @Nullable P
return yaml;
} catch (Throwable t) {
sample.stop(MetricsHelper.errorTags(timer, t).register(Metrics.globalRegistry));
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, this, t);
ParsingExecutionContextView.view(ctx).parseFailure(sourceFile, relativeTo, this, t);
ctx.getOnError().accept(new IllegalStateException(path + " " + t.getMessage(), t));
return null;
}
Expand Down

0 comments on commit cc97c47

Please sign in to comment.