Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exception or validation errors #64

Open
barryvdh opened this issue Dec 11, 2017 · 1 comment
Open

Throw exception or validation errors #64

barryvdh opened this issue Dec 11, 2017 · 1 comment

Comments

@barryvdh
Copy link

Currently, when importing products with failing validation, it will fail silently, which is confusing. This can be caught using something like this (I guess?)

$importer->processImport($products);

if (!$importer->getValidationResult()) {
       print_r($products));
       echo $importer->getLogTrace();
}

But that gives a trace for all products. Would it make more sense to throw the validation errors as an exception, preferably with the invalid rows?

@koenner01
Copy link
Contributor

I just added a pull request #70 for this :)

The PR contains our long outstanding fix (we are using this logic for 4 projects now);
This allows for something in the lines of:

$success = $importerModel->processImport($data);
// Output the importer trace
$importerLog = preg_split('/\n|\r/', $importerModel->getLogTrace(), null, PREG_SPLIT_NO_EMPTY);
foreach($importerLog as $log) {
    $this->logger->addInfo(preg_replace('/(\d:)/', '--', $log));
}
// If the processImport failed we want to throw an exception
if ($success === false) {
    throw new \Exception('Validation failed');
}

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

No branches or pull requests

2 participants