CSV uploads for redirection result in a 500 error if the temporary file is unavailable for any reason on the server.

Created on 5 October 2023, about 1 year ago
Updated 14 March 2024, 8 months ago

Problem/Motivation

This issue occurs on the production server, where the CSV file uploads successfully. However, when submitting the migration form, the uploaded file is not available for some unknown reason. This scenario throws a PHP exception, which is not handled in the module.

League\Csv\UnavailableStream: `temporary://path_redirect_import/redirect_bulk-1.csv`: failed to open stream: No such file or directory. in /var/www/html/vendor/league/csv/src/UnavailableStream.php:25 Stack trace: #0 /var/www/html/vendor/league/csv/src/Stream.php(125): League\Csv\UnavailableStream::dueToPathNotFound('temporary://pat...') #1 /var/www/html/vendor/league/csv/src/AbstractCsv.php(114): League\Csv\Stream::createFromPath('temporary://pat...', 'r', NULL) #2 /var/www/html/vendor/league/csv/src/Reader.php(54): League\Csv\AbstractCsv::createFromPath('temporary://pat...', 'r', NULL) #3 /var/www/html/docroot/modules/contrib/path_redirect_import/src/Form/MigrateRedirectForm.php(171): League\Csv\Reader::createFromPath('temporary://pat...', 'r') #4 [internal function]: Drupal\path_redirect_import\Form\MigrateRedirectForm->validateForm(Array, Object(Drupal\Core\Form\FormState)) #5 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array(Array, Array) #6 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormValidator.php(275): Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object(Drupal\Core\Form\FormState)) #7 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'migrate_redirec...') #8 /var/www/html/docroot/modules/contrib/autosave_form/src/Form/AutosaveFormValidator.php(69): Drupal\Core\Form\FormValidator->validateForm('migrate_redirec...', Array, Object(Drupal\Core\Form\FormState)) #9 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\autosave_form\Form\AutosaveFormValidator->validateForm('migrate_redirec...', Array, Object(Drupal\Core\Form\FormState)) #10 /var/www/html/docroot/modules/contrib/autosave_form/src/Form/AutosaveFormBuilder.php(144): Drupal\Core\Form\FormBuilder->processForm('migrate_redirec...', Array, Object(Drupal\Core\Form\FormState)) #11 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\autosave_form\Form\AutosaveFormBuilder->processForm('migrate_redirec...', Array, Object(Drupal\Core\Form\FormState)) #12 /var/www/html/docroot/modules/contrib/autosave_form/src/Form/AutosaveFormBuilder.php(97): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\path_redirect_import\Form\MigrateRedirectForm), Object(Drupal\Core\Form\FormState)) #13 /var/www/html/docroot/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\autosave_form\Form\AutosaveFormBuilder->buildForm(Object(Drupal\path_redirect_import\Form\MigrateRedirectForm), Object(Drupal\Core\Form\FormState)) #14 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #15 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #16 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(592): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #17 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #18 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(182): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #21 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/html/docroot/modules/contrib/shield/src/ShieldMiddleware.php(270): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/html/docroot/modules/contrib/shield/src/ShieldMiddleware.php(137): Drupal\shield\ShieldMiddleware->bypass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\shield\ShieldMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /var/www/html/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #32 {main}

Steps to reproduce

  1. Go to admin/config/search/redirect/migrate
  2. Upload csv file
  3. Delete the uploaded csv file from temporary folder of the project
  4. Click Migrate data

Proposed resolution

Handle the exception and display exception message in form validation errors.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024