cancel
Showing results for 
Search instead for 
Did you mean: 

Get concrete error message of CouldNotSaveException

Get concrete error message of CouldNotSaveException

We need to get concrete error message when Magento\Catalog\Model\ProductRepository throws CouldNotSaveException during saveProduct()

private function saveProduct($product): void
{
    try {
        $this->removeProductFromLocalCacheBySku($product->getSku());
        $this->removeProductFromLocalCacheById($product->getId());
        $this->resourceModel->save($product);
    } catch (ConnectionException $exception) {
...
    } catch (\Exception $e) {
        throw new CouldNotSaveException(
            __('The product was unable to be saved. Please try again.'),
            $e
        );
    }
}

An easy way would be just adding the message in that code

__('The product was unable to be saved. Please try again.' . $e->getMessage())

But we can't edit that file, as this is a project hosted in Adobe Cloud. So, how can we get that message instead of application default message?

2 REPLIES 2

Re: Get concrete error message of CouldNotSaveException

Hello @iamzain16g69d6 

 

Regarding edit error message, we can use translation via csv.
Please follow below steps:

 

To add translation csv file in magento2, you just need to add a folder named:

“i18n” inside your module’s folder, i.e.

app/code/Vendor/Module/i18n/en_US.csv

Add message string in csv and translation as well.
Example:
"String","translation of that strring"

 

It may help you!
Thank you

Problem solved? Click Accept as Solution!

Re: Get concrete error message of CouldNotSaveException

Hello @iamzain16g69d6 ,

 

Adobe commerce cloud infra has pretty well architecture so it is from some of your code/database, not from any directory permission or service.

the best approach is to get the project on your local system, same database dump and then change in your local machine vendor folder whatever you want for debugging. (it will be easy to debug and neither the code will be pushed to your commerce cloud project and also it will be good for long term debugging and fixing issues).

below commands will help to get project on your local system : 

https://devdocs.magento.com/cloud/before/before-setup-env-2_clone.html

 

and if you don't wish to setup on local machine then the bad approach is to override that class and rewrite that function in a custom module but it is not recommended to change or override core functions to debug.

 

before you follow above approaches, check below files inside var/log folder: 

exception.log

system.log

and other related files.

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy