Skip to content

Commit

Permalink
fix: correct error handling message on unknown
Browse files Browse the repository at this point in the history
\### Rationale
Make the error messages relevant to the function calling it since now
we are using the same function as a layer of abstraction related to
processing/digging into a CallExpression structure.
  • Loading branch information
codejedi365 committed Oct 23, 2021
1 parent e3266da commit a1604e8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/utils/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ function digForIdentifierName(startNode: BaseNode): string {
}

// Start Point
try {
if (!checkTypeForRecursion(startNode)) throw new Error();
return deriveFnName(startNode);
} catch (e) {
throw new Error("Could not derive function name from callee.");
}
if (!checkTypeForRecursion(startNode)) throw new Error();
return deriveFnName(startNode);
}

export function deriveFunctionName(fnCall: CallExpression): string {
Expand All @@ -61,7 +57,11 @@ export function deriveFunctionName(fnCall: CallExpression): string {
? fnCall.callee.property
: fnCall.callee;

return digForIdentifierName(startNode);
try {
return digForIdentifierName(startNode);
} catch (e) {
throw new Error("Could not derive function name from callee.");
}
}

/**
Expand All @@ -74,7 +74,11 @@ export function deriveFunctionName(fnCall: CallExpression): string {
* @returns top level symbol for name of object
*/
export function deriveObjectName(fnCall: CallExpression): string {
return digForIdentifierName(fnCall.callee);
try {
return digForIdentifierName(fnCall.callee);
} catch (e) {
throw new Error("Could not derive object name from callee.");
}
}

export function determineCodeLocation(
Expand Down

0 comments on commit a1604e8

Please sign in to comment.