? .DS_Store
? .cache
? .git
? .project
? .settings
? empty
? file_278425.patch
? file_334303_3.patch
? file_exceptions.patch
? file_load_multiple_3.patch
? file_load_multiple_5.patch
? logs
? test.php
? sites/.DS_Store
? sites/all/.DS_Store
? sites/all/modules
? sites/default/.DS_Store
? sites/default/files
? sites/default/settings.php
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.837
diff -u -p -r1.837 common.inc
--- includes/common.inc	12 Dec 2008 16:07:13 -0000	1.837
+++ includes/common.inc	19 Dec 2008 07:14:15 -0000
@@ -41,6 +41,27 @@ define('JS_DEFAULT', 0);
 define('JS_THEME', 100);
 
 /**
+ * A base class for Drupal exceptions.
+ *
+ * Uses t() to translate the strings.
+ */
+class DrupalException extends Exception {
+  /**
+   * Use t() to construct the error message.
+   *
+   * @param $string
+   *   Message string
+   * @param $args
+   *   Optional, array with arguments for t().
+   * @param $form_element
+   *   The name of a form element responsible for the error.
+   */
+  public function __construct($string, $args = array(), $form_element = NULL) {
+    parent::__construct(t($string, $args), 0);
+  }
+}
+
+/**
  * Set content for a specified region.
  *
  * @param $region
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.146
diff -u -p -r1.146 file.inc
--- includes/file.inc	4 Dec 2008 11:09:33 -0000	1.146
+++ includes/file.inc	19 Dec 2008 07:14:15 -0000
@@ -85,6 +85,20 @@ define('FILE_STATUS_TEMPORARY', 0);
 define('FILE_STATUS_PERMANENT', 1);
 
 /**
+ * File specific exceptions.
+ */
+class FileException extends DrupalException {
+  public function __construct($string, $args = array(), $form_element = NULL) {
+    parent::__construct($string, $args, $form_element);
+  }
+}
+
+/**
+ * File specific exceptions.
+ */
+class FileException extends DrupalException { }
+
+/**
  * Create the download path to a file.
  *
  * @param $path A string containing the path of the file to generate URL for.
@@ -169,8 +183,7 @@ function file_check_directory(&$director
     }
     else {
       if ($form_item) {
-        form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => $directory)));
-        watchdog('file system', 'The directory %directory does not exist.', array('%directory' => $directory), WATCHDOG_ERROR);
+        throw new FileException('The directory %directory does not exist.', array('%directory' => $directory), $form_item);
       }
       return FALSE;
     }
@@ -182,8 +195,7 @@ function file_check_directory(&$director
     // fails, return false.
     if (!$mode || (($mode & FILE_MODIFY_PERMISSIONS) && !@chmod($directory, 0775))) {
       if ($form_item) {
-        form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
-        watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
+        throw new FileException('The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), $form_item);
       }
       return FALSE;
     }
@@ -197,8 +209,7 @@ function file_check_directory(&$director
     }
     else {
       $variables = array('%directory' => $directory, '!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)));
-      form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables));
-      watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
+      throw new FileException("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, $form_item);
     }
   }
 
@@ -431,8 +442,7 @@ function file_copy($source, $destination
 function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
   $source = realpath($source);
   if (!file_exists($source)) {
-    drupal_set_message(t('The specified file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source)), 'error');
-    return FALSE;
+    throw new Exception('The specified file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source));
   }
 
   $destination = file_create_path($destination);
@@ -441,8 +451,7 @@ function file_unmanaged_copy($source, $d
 
   // Make sure we at least have a valid directory.
   if ($basename === FALSE) {
-    drupal_set_message(t('The specified file %file could not be copied, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $destination)), 'error');
-    return FALSE;
+    throw new FileException('The specified file %file could not be copied, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $destination));
   }
 
   // If the destination file is not specified then use the filename of the
@@ -451,19 +460,16 @@ function file_unmanaged_copy($source, $d
   $destination = file_destination($directory . '/' . $basename, $replace);
 
   if ($destination === FALSE) {
-    drupal_set_message(t('The specified file %file could not be copied because a file by that name already exists in the destination.', array('%file' => $source)), 'error');
-    return FALSE;
+    throw new FileException('The specified file %file could not be copied because a file by that name already exists in the destination.', array('%file' => $source));
   }
   // Make sure source and destination filenames are not the same, makes no
   // sense to copy it if they are. In fact copying the file will most likely
   // result in a 0 byte file. Which is bad. Real bad.
   if ($source == realpath($destination)) {
-    drupal_set_message(t('The specified file %file was not copied because it would overwrite itself.', array('%file' => $source)), 'error');
-    return FALSE;
+    throw new FileException('The specified file %file was not copied because it would overwrite itself.', array('%file' => $source));
   }
   if (!@copy($source, $destination)) {
-    drupal_set_message(t('The specified file %file could not be copied.', array('%file' => $source)), 'error');
-    return FALSE;
+    throw new FileException('The specified file %file could not be copied.', array('%file' => $source));
   }
 
   // Give everyone read access so that FTP'd users or
@@ -505,8 +511,7 @@ function file_destination($destination, 
         break;
 
       case FILE_EXISTS_ERROR:
-        drupal_set_message(t('The specified file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $destination)), 'error');
-        return FALSE;
+        throw new FileException('The specified file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $destination));
     }
   }
   return $destination;
@@ -552,7 +557,7 @@ function file_move($source, $destination
       module_invoke_all('file_move', $file, $source);
       return $file;
     }
-    drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $source->filepath)), 'error');
+    throw new FileException('The removal of the original file %file has failed.', array('%file' => $source->filepath));
   }
   return FALSE;
 }
@@ -741,8 +746,7 @@ function file_delete($file, $force = FAL
  */
 function file_unmanaged_delete($path) {
   if (is_dir($path)) {
-    watchdog('file', '%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path), WATCHDOG_ERROR);
-    return FALSE;
+    throw new FileException('%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path));
   }
   if (is_file($path)) {
     return unlink($path);
@@ -824,18 +828,15 @@ function file_save_upload($source, $vali
 
       case UPLOAD_ERR_INI_SIZE:
       case UPLOAD_ERR_FORM_SIZE:
-        drupal_set_message(t('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $source, '%maxsize' => format_size(file_upload_max_size()))), 'error');
-        return FALSE;
+        throw new FileException('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $source, '%maxsize' => format_size(file_upload_max_size())));
 
       case UPLOAD_ERR_PARTIAL:
       case UPLOAD_ERR_NO_FILE:
-        drupal_set_message(t('The file %file could not be saved, because the upload did not complete.', array('%file' => $source)), 'error');
-        return FALSE;
+        throw new FileException('The file %file could not be saved, because the upload did not complete.', array('%file' => $source));
 
         // Unknown error
       default:
-        drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $source)), 'error');
-        return FALSE;
+        throw new FileException('The file %file could not be saved. An unknown error has occurred.', array('%file' => $source));
     }
 
     // Build the list of non-munged extensions.
@@ -883,8 +884,7 @@ function file_save_upload($source, $vali
       else {
         $message .= ' ' . array_pop($errors);
       }
-      form_set_error($source, $message);
-      return FALSE;
+      throw new FileException($message, array(), $source);
     }
 
     // Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary
@@ -892,9 +892,8 @@ function file_save_upload($source, $vali
     // operations.
     $file->filepath = $file->destination;
     if (!move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->filepath)) {
-      form_set_error($source, t('File upload error. Could not move uploaded file.'));
-      watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->filepath));
-      return FALSE;
+      throw new FileException('File upload error. Could not move uploaded file.', array(), $source);
+//      watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->filepath));
     }
 
     // If we made it this far it's safe to record this file in the database.
@@ -1167,8 +1166,7 @@ function file_unmanaged_save_data($data,
   // Write the data to a temporary file.
   $temp_name = tempnam(file_directory_temp(), 'file');
   if (file_put_contents($temp_name, $data) === FALSE) {
-    drupal_set_message(t('The file could not be created.'), 'error');
-    return FALSE;
+    throw new FileException('The file could not be created.');
   }
 
   // Move the file to its final destination.
