Error Handlings
Published: 2023-09-04 06:50:55

## Error: Malfunctioning Elasticsearch

#### Symptoms

```ruby
Unable to apply data patch
Magento\CatalogSampleData\Setup\Patch\Data\InstallSimpleProducts 
for module Magento_CatalogSampleData.
```

```ruby
{"error":"no handler found for uri [/magento2_product_1_v1/document_mapping?include_type_name=true] and method [PUT]"}
```

#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7w10b7u7i1b98tf2b0ue.png)

#### 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:

```php
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;   
}
```

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

---

## Error: PluginListGenerator.php on line 411

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l2o3t8hg9m0ix28j1zlt.png)

#### Solution

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

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

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

We only changed the `|` -> `-` character.

---

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64aiqfu507nphtfkqg34.png)

Add extra code in

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

```php
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; }
```

#### Sources:

- https://magento.stackexchange.com/a/344211/113111

---

## Error: `require-config.js` is not a function 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9u0f7mf17470st79g4z.png)

#### 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/"
```

---


## Error: Image not displaying

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cid8kdivlbxk2hlv7msb.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyngc391r241msg3ksxu.png)

#### Solution

Run this command
```
bin/magento catalog:image:resize
```

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbful3ebeoaeowp3s443.png)

---

## 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/
```

```
composer config http-basic.repo.magento.com a0a6f216e5da943ce3a36ac92d430456 b0436530e2c686c94e1ad8948411aa55
```

#### Sources:

- https://github.com/magento/magento2/issues/2520#issuecomment-638293942 


## Error: `bin/magento` Permission Denied

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

## Error: The default website isn't defined

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5d0bkqirjtzq6qulvnjt.png)

Remove `app/etc/env.php`