diff -u b/core/modules/file/file.module b/core/modules/file/file.module --- b/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -970,14 +970,14 @@ default: // Unknown error - $error_to_log = 'The file ' . $file_info->getFilename() . ' could not be saved. An unknown error has occurred.'; + $error_to_log = 'The file ' . $original_file_name . ' could not be saved. An unknown error has occurred.'; break; } if (isset($error_to_log)) { // Unconditionally display an error message to the end user. This is a // generic message since the errors that trigger this represent server-level - // problems that end users should not know about (and cannot fix by - // attempting the upload again). + // problems that end users should not know about and cannot fix by + // attempting the upload again. \Drupal::messenger()->addError(t('The file %file could not be saved. An unknown error has occurred.', ['%file' => $original_file_name])); \Drupal::logger('file')->error($error_to_log); return FALSE; diff -u b/core/modules/file/tests/src/Kernel/FileModuleTest.php b/core/modules/file/tests/src/Kernel/FileModuleTest.php --- b/core/modules/file/tests/src/Kernel/FileModuleTest.php +++ b/core/modules/file/tests/src/Kernel/FileModuleTest.php @@ -36,7 +36,7 @@ $this->assertFalse(\_file_save_upload_single($file_info, 'name')); // Check the displayed user message. - $expected_message = new TranslatableMarkup("The file %file could not be saved. An unknown error has occurred.", ['%file' => $file_name]); + $expected_message = new TranslatableMarkup('The file %file could not be saved. An unknown error has occurred.', ['%file' => $file_name]); $this->assertEquals($expected_message, \Drupal::messenger()->all()['error'][0]); // Check the logged message.