Importer RowImportFailedException

I've created an importer that is supposed to bail if it encounters references to data that doesn't exist in my database. However, when I run a test using a CSV with 1 valid row and 1 invalid row, the exception is thrown but the importer then ends up in an infinite loop and I get multiple copies of the valid row imported until I kill the queue. Here's my resolveRecord function that is intended to throw the exception:
public function resolveRecord(): ?InvoiceItem
{
$invoiceNumber = $this->data['invoice_number'];
$invoice = Invoice::query()
->where('invoice_number', $invoiceNumber)
->first();

$productSku = $this->data['product_sku'];
$product = Product::query()
->where('sku', $productSku)
->first();

if ($invoice == NULL || $product == NULL) {
throw new RowImportFailedException("Product with SKU [{$this->data['product_sku']}] and/or Invoice with Name [{$this->data['invoice_number']}] not found.");
}

$newInvoiceItem = new InvoiceItem();
$newInvoiceItem->invoice_id = $invoice->id;
$newInvoiceItem->product_id = $product->id;

return $newInvoiceItem;
}
public function resolveRecord(): ?InvoiceItem
{
$invoiceNumber = $this->data['invoice_number'];
$invoice = Invoice::query()
->where('invoice_number', $invoiceNumber)
->first();

$productSku = $this->data['product_sku'];
$product = Product::query()
->where('sku', $productSku)
->first();

if ($invoice == NULL || $product == NULL) {
throw new RowImportFailedException("Product with SKU [{$this->data['product_sku']}] and/or Invoice with Name [{$this->data['invoice_number']}] not found.");
}

$newInvoiceItem = new InvoiceItem();
$newInvoiceItem->invoice_id = $invoice->id;
$newInvoiceItem->product_id = $product->id;

return $newInvoiceItem;
}
The exception gets logged in my laravel.log file, but I do not see any results in the UI for the import.
Solution:
Turns out it was a simple solution. I hadn't included the RowImportFailedException type in the file and so the exception being thrown was actually a class not found exception. I didn't notice that!...
Jump to solution
1 Reply
Solution
ChickenDev
ChickenDev2mo ago
Turns out it was a simple solution. I hadn't included the RowImportFailedException type in the file and so the exception being thrown was actually a class not found exception. I didn't notice that!
Want results from more Discord servers?
Add your server