Skip to content

Commit

Permalink
Handle missing node locations in composition error (#362)
Browse files Browse the repository at this point in the history
Fixes #361

Co-authored-by: Avery Harnish <[email protected]>
  • Loading branch information
michael-watson and EverlastingBugstopper authored Jul 6, 2023
1 parent 0f852ec commit 5c9ee90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
13 changes: 8 additions & 5 deletions federation-1/harmonizer/js-src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ export function composition(
composed.errors.map((err) => {
let nodes: BuildErrorNode[] = [];
err.nodes.map((node) => {
nodes.push({
let n: BuildErrorNode = {
subgraph: (node as any)?.subgraph,
source: node?.loc.source.body,
start: getPosition(node.loc.startToken),
end: getPosition(node.loc.endToken),
});
};
if (node.loc) {
n.source = node?.loc?.source?.body;
n.start = getPosition(node.loc.startToken);
n.end = getPosition(node.loc.endToken);
}
nodes.push(n);
});

errors.push({
Expand Down
30 changes: 14 additions & 16 deletions federation-2/harmonizer/js-src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ export function composition(
if (composed.hints) {
composed.hints.map((composed_hint) => {
let nodes: BuildErrorNode[] = [];
composed_hint.nodes?.map((node) => {
nodes.push({
subgraph: (node as any)?.subgraph,
source: node?.loc.source.body,
start: getPosition(node.loc.startToken),
end: getPosition(node.loc.endToken),
});
});
composed_hint.nodes?.map((node) => nodes.push(getBuildErrorNode(node)));

hints.push({
message: composed_hint.toString(),
Expand All @@ -60,14 +53,7 @@ export function composition(
let errors: CompositionError[] = [];
composed.errors.map((err) => {
let nodes: BuildErrorNode[] = [];
err.nodes?.map((node) => {
nodes.push({
subgraph: (node as any)?.subgraph,
source: node?.loc.source.body,
start: getPosition(node.loc.startToken),
end: getPosition(node.loc.endToken),
});
});
err.nodes?.map((node) => nodes.push(getBuildErrorNode(node)));

errors.push({
code: (err?.extensions["code"] as string) ?? "",
Expand All @@ -86,6 +72,18 @@ export function composition(
};
}

function getBuildErrorNode(node: ASTNode) {
let n: BuildErrorNode = {
subgraph: (node as any)?.subgraph,
};
if (node.loc) {
n.source = node.loc?.source?.body;
n.start = getPosition(node.loc.startToken);
n.end = getPosition(node.loc.endToken);
}
return n;
}

function getPosition(token: Token): Position {
return {
start: token.start,
Expand Down

0 comments on commit 5c9ee90

Please sign in to comment.