DEV Community

Jack Huynh
Jack Huynh

Posted on

Error Handlings

Error: Malfunctioning Elasticsearch

Symptoms

Unable to apply data patch
Magento\CatalogSampleData\Setup\Patch\Data\InstallSimpleProducts 
for module Magento_CatalogSampleData.
Enter fullscreen mode Exit fullscreen mode
{"error":"no handler found for uri [/magento2_product_1_v1/document_mapping?include_type_name=true] and method [PUT]"}
Enter fullscreen mode Exit fullscreen mode

Solution

Due to ElasticSearch version is not yet supported by the current Magento instance: https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html.

Just install Elasticsearch 7.17


Error: Gd2.php line 70

Image description

Solution

Here Image Adapter try opens to image files (‘open function in Gd2.php line 72). validateURLScheme function return false always because it checking ‘URL’ format but local files not valid for this format, so it returns false.

Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 92. Replace function with this:

private function validateURLScheme(string $filename) : bool
{
          $allowed_schemes = ['ftp', 'ftps', 'http', 'https'];
          $url = parse_url($filename);
          if ($url && isset($url['scheme']) && !in_array($url['scheme'], $allowed_schemes) && !file_exists($filename)) {
              return false;
          }

          return true;   
}
Enter fullscreen mode Exit fullscreen mode

Only change is && !file_exists($filename) text added at line 96.


Error: PluginListGenerator.php on line 411

Image description

Solution

Find write(array $scopes) function in magento2\lib\internal\Magento\Framework\Interception\PluginListGenerator.php file. at line 156.

// Replace
$cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId;

// With
$cacheId = implode('-', $this->scopePriorityScheme) . "-" . $this->cacheId;
Enter fullscreen mode Exit fullscreen mode

We only changed the | -> - character.


Error Magento\Framework\Exception\ValidatorException: Invalid template file

Image description

Add extra code in

magento2\lib\internal\Magento\Framework\View\Element\Template\File\Validator.php file

protected function isPathInDirectories($path, $directories) {
     if (!is_array($directories)) {
         $directories = (array)$directories;
     }
     $realPath = $this->fileDriver->getRealPath($path);
     $realPath = str_replace('\\', '/', $realPath); // extra code added
     foreach ($directories as $directory) {
         if (0 === strpos($realPath, $directory)) {
             return true;
         }
     }
     return false; }
Enter fullscreen mode Exit fullscreen mode

Sources:


Error: require-config.js is not a function

Image description

Solution

Change the project base-config "base-url" from "http://localhost/magento2" to " http://localhost/magento2/pub"

bin/magento setup:store-config:set --base-url="http://localhost/magento2/pub/"
Enter fullscreen mode Exit fullscreen mode

Error: Image not displaying

Image description

Image description

Solution

Run this command

bin/magento catalog:image:resize
Enter fullscreen mode Exit fullscreen mode

Be patience cause this seemingly simple command could take half and hour

Image description


Error: The requested package magento/module-bundle-sample-data could not be found in any version, there may be a typo in the package name

Solution

composer config repositories.magento composer https://repo.magento.com/
Enter fullscreen mode Exit fullscreen mode
composer config http-basic.repo.magento.com a0a6f216e5da943ce3a36ac92d430456 b0436530e2c686c94e1ad8948411aa55
Enter fullscreen mode Exit fullscreen mode

Sources:

Error: bin/magento Permission Denied

https://magefan.com/blog/bin-magento-permission-denied

Error: The default website isn't defined

Image description

Remove app/etc/env.php

Top comments (0)