Improved error reporting if loading capture configuration file fails
authorEric Biggers <ebiggers3@gmail.com>
Sun, 3 May 2015 21:35:11 +0000 (16:35 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 3 May 2015 21:57:59 +0000 (16:57 -0500)
include/wimlib.h
src/capture_common.c
src/error.c

index 2dcbd12d3d7e7c545d9b61ebd87eefe644d27d39..81e8f09c656f8260d80c47d267bd0c8e21bd13de 100644 (file)
@@ -2451,6 +2451,7 @@ enum wimlib_error_code {
        WIMLIB_ERR_NOT_A_MOUNTPOINT                   = 80,
        WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT           = 81,
        WIMLIB_ERR_FVE_LOCKED_VOLUME                  = 82,
+       WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG      = 83,
 };
 
 
@@ -4244,8 +4245,7 @@ wimlib_unmount_image_with_progress(const wimlib_tchar *dir,
  *     Windows-only: One of the "add" commands attempted to add files from an
  *     encrypted BitLocker volume that hasn't yet been unlocked.
  * @retval ::WIMLIB_ERR_INVALID_CAPTURE_CONFIG
- *     The capture configuration structure specified for an add command was
- *     invalid.
+ *     The contents of a capture configuration file were invalid.
  * @retval ::WIMLIB_ERR_INVALID_IMAGE
  *     @p image did not exist in @p wim.
  * @retval ::WIMLIB_ERR_INVALID_OVERLAY
@@ -4292,6 +4292,8 @@ wimlib_unmount_image_with_progress(const wimlib_tchar *dir,
  * @retval ::WIMLIB_ERR_STAT
  *     While executing an add command, failed to get attributes for a file or
  *     directory.
+ * @retval ::WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG
+ *     A capture configuration file could not be read.
  * @retval ::WIMLIB_ERR_UNSUPPORTED
  *     ::WIMLIB_ADD_FLAG_NTFS was specified in the @p add_flags for an update
  *     command, but wimlib was configured with the @c --without-ntfs-3g flag;
index 0e6826194ce47f0b3efd9c6c6e87d670354a8f6a..e544b7c126794f0e5013b684d9c3d83f455058de 100644 (file)
@@ -203,8 +203,25 @@ read_capture_config(const tchar *config_file, const void *buf,
        ret = do_load_text_file(config_file, buf, bufsize, &mem,
                                sections, ARRAY_LEN(sections),
                                LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_pat);
-       if (ret)
+       if (ret) {
+               ERROR("Failed to load capture configuration file \"%"TS"\"",
+                     config_file);
+               switch (ret) {
+               case WIMLIB_ERR_INVALID_UTF8_STRING:
+               case WIMLIB_ERR_INVALID_UTF16_STRING:
+                       ERROR("Note: the capture configuration file must be "
+                             "valid UTF-8 or UTF-16LE");
+                       ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
+                       break;
+               case WIMLIB_ERR_OPEN:
+               case WIMLIB_ERR_STAT:
+               case WIMLIB_ERR_NOMEM:
+               case WIMLIB_ERR_READ:
+                       ret = WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG;
+                       break;
+               }
                return ret;
+       }
 
        FREE(prepopulate_pats.strings);
        FREE(compression_exclusion_pats.strings);
index 49f83294ca277060683811ce1bc6a842db681f9b..ed9e6b72be56772f444c58932c79054e888370d9 100644 (file)
@@ -220,7 +220,7 @@ static const tchar * const error_strings[] = {
        [WIMLIB_ERR_INTEGRITY]
                = T("The WIM file is corrupted (failed integrity check)"),
        [WIMLIB_ERR_INVALID_CAPTURE_CONFIG]
-               = T("The capture configuration string was invalid"),
+               = T("The contents of the capture configuration file were invalid"),
        [WIMLIB_ERR_INVALID_CHUNK_SIZE]
                = T("The compression chunk size was unrecognized"),
        [WIMLIB_ERR_INVALID_COMPRESSION_TYPE]
@@ -354,6 +354,8 @@ static const tchar * const error_strings[] = {
                = T("The current user does not have permission to unmount the WIM image"),
        [WIMLIB_ERR_FVE_LOCKED_VOLUME]
                = T("The volume must be unlocked before it can be used"),
+       [WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG]
+               = T("The capture configuration file could not be read"),
 };
 
 WIMLIBAPI const tchar *