maotoumao/MusicFree · warning · Error

搜索结果为空

Error message

搜索结果为空

What it means

useSearch throws Error('搜索结果为空') ("search result is empty") when the search hook receives a falsy result back from the plugin search call. It guards the state update so empty/failed plugin responses never overwrite existing results. The page status is set to RESULT only when not in EDITING mode.

Solutions

  1. Check network connectivity and retry the search.
  2. Update the search plugin for the selected platform so its search returns a valid result object.
  3. In the plugin, return an empty result structure ({data: [], ...}) instead of null/undefined for zero-hit searches.
  4. Wrap the search call so a null result is shown as 'no results' UI rather than propagating an exception.

Example fix

// before
const result = await plugin.methods.search(keyword, page, type);
// after
const result = (await plugin.methods.search(keyword, page, type)) ?? { isEnd: true, data: [] };
Defensive patterns

Strategy: try-catch

Validate before calling

if (!keyword?.trim()) return; // don't even call search
const plugin = pluginManagerService.getBySearchType(searchType);
if (!plugin?.methods?.search) { setNoResults(); return; }

Type guard

function isSearchResult(r: unknown): boolean {
  return !!r && typeof r === 'object' && Array.isArray((r as any).data);
}

Try / catch

try {
  await search(keyword);
} catch (e) {
  if (e?.message === '搜索结果为空') {
    setPageStatus(PageStatus.RESULT); // show empty state, keep old data
  } else {
    Toast.warn(e?.message ?? String(e));
  }
}

Prevention

When it happens

Trigger: Invoking the search function of useSearch where the plugin's search() resolves to undefined/null/empty — e.g. plugin returns no data, keyword yields zero results with no result envelope, or the plugin throws and is caught upstream returning nothing.

Common situations: Searching with a plugin whose remote API changed or is down; entering keywords that match nothing and the plugin returns null instead of an empty list; stale plugin after a music-site redesign; searching while offline.

Related errors


AI-assisted analysis of maotoumao/MusicFree@d118b18b3d (2026-08-30). Data as JSON: /api/errors/c7d7ad740e1fa49b. Report an issue: GitHub.

Appendix: source

Thrown at src/pages/searchPage/hooks/useSearch.ts:124

                    );
                    // !! jscore的promise有问题,改成hermes就好了,可能和JIT有关,不知道。
                    const result = await plugin?.methods?.search?.(
                        query,
                        page,
                        searchType,
                    );
                    /** 如果搜索结果不是本次结果 */
                    if (currentQueryRef.current !== query) {
                        return;
                    }
                    /** 切换到结果页 */
                    const currentPageStatus =
                        getDefaultStore().get(pageStatusAtom);
                    if (currentPageStatus !== PageStatus.EDITING) {
                        setPageStatus(PageStatus.RESULT);
                    }
                    if (!result) {
                        throw new Error("搜索结果为空");
                    }
                    setSearchResults(
                        produce(draft => {
                            const prevMediaResult = draft[searchType];
                            const prevPluginResult: any = prevMediaResult[
                                _hash
                            ] ?? {
                                data: [],
                            };
                            const currResult = result.data ?? [];

                            prevMediaResult[_hash] = {
                                state:
                                    result?.isEnd === false &&
                                        result?.data?.length
                                        ? RequestStateCode.PARTLY_DONE
                                        : RequestStateCode.FINISHED,
                                query,

View on GitHub (pinned to d118b18b3d)