Shopify / Shopify/shopify-app-template-php
Resolving TypeError: Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 340
- Forks
- 108
- PR merge metrics
- No merged PRs in 30d
Description
Overview/summary
As well as many others I often get the following error too:
TypeError: Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /app/app/Lib/AuthRedirection.php on line 17 in file /app/vendor/shopify/shopify-api/src/Utils.php on line 36
It occurs when the webserver gets a malformed call (without the shop parameter basically), and this may happen for many reasons.
(In my opinion this looks more like a bug then an enhancement, but the application still works even if the log files gets filled with plenty of lines of this error)
Motivation
The function Shopify\Utils::sanitizeShopDomain should be called either with an empty string as fallback for its first parameter: Utils::sanitizeShopDomain($request->query("shop", '')) like HERE,
or with a guard on the first parameter: $shop = $request->query('shop') ? Utils::sanitizeShopDomain($request->query('shop')) : null; like HERE
(Then the code should deal with the case $shop = null of course), otherwise it throws a TypeError exception because $request->query('shop') returns null and not a string (as requested by the signature of Utils::sanitizeShopDomain) if the shop variable is missing from the query params.
Relevant lines in the code:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with web/app/Lib/AuthRedirection.php line 17 and compare its shop query handling with EnsureShopifyInstalled.php line 22. Trace the /api/auth and /api/auth/callback routes in web/routes/web.php, then verify that requests missing the shop parameter are handled without passing null to Shopify\Utils::sanitizeShopDomain() or producing the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100