Skip to content

Commit 00ff716

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
improve error message on components + crons (#28995)
before: ``` Failed to analyze crons.js: Uncaught TypeError: Cannot convert object to primitive value ``` after: ``` Failed to analyze crons.js: Uncaught Error: Expected function reference in the current component like "api.file.func" or "internal.file.func", but received reference _reference/childComponent/waitlist/sendMessage ``` GitOrigin-RevId: aaeb49d9817d1e5decccbb450d0e14db8b96978f
1 parent 65f0c76 commit 00ff716

File tree

1 file changed

+17
-0
lines changed
  • npm-packages/convex/src/server

1 file changed

+17
-0
lines changed

npm-packages/convex/src/server/api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "./registration.js";
99
import { Expand, UnionToIntersection } from "../type_utils.js";
1010
import { PaginationOptions, PaginationResult } from "./pagination.js";
11+
import { getFunctionAddress } from "./impl/actions_impl.js";
1112

1213
/**
1314
* The type of a Convex function.
@@ -81,6 +82,22 @@ export const functionName = Symbol.for("functionName");
8182
export function getFunctionName(
8283
functionReference: AnyFunctionReference,
8384
): string {
85+
const address = getFunctionAddress(functionReference);
86+
87+
if (address.name === undefined) {
88+
if (address.functionHandle !== undefined) {
89+
throw new Error(
90+
`Expected function reference like "api.file.func" or "internal.file.func", but received function handle ${address.functionHandle}`,
91+
);
92+
} else if (address.reference !== undefined) {
93+
throw new Error(
94+
`Expected function reference in the current component like "api.file.func" or "internal.file.func", but received reference ${address.reference}`,
95+
);
96+
}
97+
throw new Error(
98+
`Expected function reference like "api.file.func" or "internal.file.func", but received ${JSON.stringify(address)}`,
99+
);
100+
}
84101
// Both a legacy thing and also a convenience for interactive use:
85102
// the types won't check but a string is always allowed at runtime.
86103
if (typeof functionReference === "string") return functionReference;

0 commit comments

Comments
 (0)