Skip to content

Commit

Permalink
Fix missing type error message (#51)
Browse files Browse the repository at this point in the history
Fixes: FG-4493
  • Loading branch information
snosenzo authored Aug 11, 2023
1 parent f4dc89e commit 2e322a4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/omgidl-parser/src/IDLNodeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export class IDLNodeProcessor {
});
if (!typeNode) {
throw new Error(
`Could not find type <${type}> for field <${node.name ?? "undefined"}> in <${node.name}>`,
`Could not find type <${type}> for ${node.declarator} <${
node.name ?? "undefined"
}> in <${getParentScopedIdentifier(scopedIdentifier)}>`,
);
}
if (typeNode.declarator === "enum") {
Expand Down Expand Up @@ -186,7 +188,7 @@ export class IDLNodeProcessor {
if (typeNode.declarator === "typedef") {
// To fully support this we would need to either make multiple passes or recursively resolve typedefs
throw new Error(
`We do not support typedefs that reference other typedefs ${node.name} -> ${typeNode.name}`,
`We do not support typedefs that reference other typedefs ${node.name} -> ${type}`,
);
}
if (typeNode.declarator === "struct") {
Expand Down Expand Up @@ -413,6 +415,15 @@ function fromScopedIdentifier(path: string): string[] {
return path.split("::");
}

/** Used for error messages. Returns "global scope" when there is no parent scoped identifier */
function getParentScopedIdentifier(scopedIdentifier: string): string {
const path = fromScopedIdentifier(scopedIdentifier);
if (path.length === 1) {
return "global scope";
}
return toScopedIdentifier(path.slice(0, -1));
}

function normalizeType(type: string): string {
const toType = numericTypeMap[type];
if (toType != undefined) {
Expand Down

0 comments on commit 2e322a4

Please sign in to comment.