Skip to content

Fix search route error catch handler result being discarded#3692

Open
J8118 wants to merge 2 commits intoShopify:mainfrom
J8118:fix/search-catch-discards-result
Open

Fix search route error catch handler result being discarded#3692
J8118 wants to merge 2 commits intoShopify:mainfrom
J8118:fix/search-catch-discards-result

Conversation

@J8118
Copy link
Copy Markdown
Contributor

@J8118 J8118 commented Apr 10, 2026

Summary

In the skeleton template's search.tsx loader, the .catch() handler on searchPromise returns a fallback value, but this return value is discarded because return await searchPromise on line 33 awaits the original promise, not the one with the catch handler attached. .catch() creates a new promise chain — the original promise still rejects.

If searchPromise rejects, two things happen:

  1. The .catch() handler logs the error and returns a fallback (but this value goes nowhere)
  2. await searchPromise throws, resulting in a 500 error

File changed:

  • templates/skeleton/app/routes/search.tsx (lines 28-33)

Before:

searchPromise.catch((error: Error) => {
  console.error(error);
  return {term: '', result: null, error: error.message};
});

return await searchPromise;

After:

return await searchPromise.catch((error: Error) => {
  console.error(error);
  return {term: '', result: null, error: error.message};
});

@J8118 J8118 requested a review from a team as a code owner April 10, 2026 09:06
@fredericoo
Copy link
Copy Markdown
Contributor

nice find - the `.catch()` return value was being discarded, so the error fallback never actually reached the caller. the fix correctly chains the catch.

since this is a skeleton template change, it needs a triple changeset bump per our repo rules. could you add one?

```md

"skeleton": patch
"@shopify/cli-hydrogen": patch
"@shopify/create-hydrogen": patch

Fixed search route error handling so search errors are gracefully handled with a fallback instead of causing unhandled rejections.
```

cheers!

@J8118
Copy link
Copy Markdown
Contributor Author

J8118 commented Apr 16, 2026

Done — just pushed the triple-bump changeset

J8118 added 2 commits April 17, 2026 02:27
The .catch() was called on searchPromise but the returned chain was
not used. The original promise was awaited separately, so rejections
still threw a 500 error. Now awaiting the promise with the catch
handler so the fallback value is actually returned.
@J8118 J8118 force-pushed the fix/search-catch-discards-result branch from 824c4e4 to 9025266 Compare April 16, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants