Repository: tanstack/query
File: packages/query-core/src/infiniteQueryBehavior.ts (TypeScript)

Code before:
                cancelled = true
              } else {
                context.signal.addEventListener('abort', () => {
                  cancelled = true
                })
              }
              return context.signal
            },
          })
        }

        // Get query function
        const queryFn = context.options.queryFn

        if (!queryFn) {
          return Promise.reject(
            new Error(`Missing queryFn: '${context.options.queryHash}'`),
          )
        }

        if (queryFn === skipToken) {
          return Promise.reject(
            new Error(
              `Attempted to invoke queryFn when set to skipToken, indicating a configuration error. Query hash: '${context.options.queryHash}'`,
            ),
          )
        }

        // Create function to fetch a page
        const fetchPage = async (
          data: InfiniteData<unknown>,
          param: unknown,
          previous?: boolean,
        ): Promise<InfiniteData<unknown>> => {
          if (cancelled) {
            return Promise.reject()
          }

          if (param == null && data.pages.length) {
            return Promise.resolve(data)
          }

          const queryFnContext: Omit<
            QueryFunctionContext<QueryKey, unknown>,
            'signal'
          > = {
            queryKey: context.queryKey,
            pageParam: param,
            direction: previous ? 'backward' : 'forward',
            meta: context.options.meta,
          }

Review comment (suggestion):
I would prefer it if we'd keep the runtime errors to a minimum. What we usually do in these cases is log something in dev mode, then throw a minimal error.

for example:

https://github.com/TanStack/query/blob/c69a18a232220ff308ea82b133b9214c508e6586/packages/query-core/src/query.ts#L473-L481

Here, I'd just combine it with `Missing queryFn` from above

Code after:
                cancelled = true
              } else {
                context.signal.addEventListener('abort', () => {
                  cancelled = true
                })
              }
              return context.signal
            },
          })
        }

        // Get query function
        const queryFn =
          context.options.queryFn && context.options.queryFn !== skipToken
            ? context.options.queryFn
            : () => {
                if (process.env.NODE_ENV !== 'production') {
                  if (context.options.queryFn === skipToken) {
                    console.error(
                      `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${context.options.queryHash}'`,
                    )
                  }
                }
                return Promise.reject(
                  new Error(`Missing queryFn: '${context.options.queryHash}'`),
                )
              }

        // Create function to fetch a page
        const fetchPage = async (
          data: InfiniteData<unknown>,
          param: unknown,
          previous?: boolean,
        ): Promise<InfiniteData<unknown>> => {
          if (cancelled) {
            return Promise.reject()
          }

          if (param == null && data.pages.length) {
            return Promise.resolve(data)
          }

          const queryFnContext: Omit<
            QueryFunctionContext<QueryKey, unknown>,
            'signal'
          > = {
            queryKey: context.queryKey,
            pageParam: param,
            direction: previous ? 'backward' : 'forward',
            meta: context.options.meta,
          }