diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2008-03-18 20:08:21 +0100 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2008-03-18 20:08:21 +0100 |
commit | 185d5818fd546f85934b041d5b0cdcdf1849b1dc (patch) | |
tree | cdd5be6f36b4aa8c6c75366b0bd35bf7d53d3804 | |
parent | 9bba2748985049515bfd9c9b44f26b92fa704078 (diff) |
Improve error handling when creating a document
-rw-r--r-- | glib/poppler-document.cc | 40 | ||||
-rw-r--r-- | glib/poppler.h | 5 |
2 files changed, 32 insertions, 13 deletions
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index ef71db47..0348718d 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -70,19 +70,35 @@ _poppler_document_new_from_pdfdoc (PDFDoc *newDoc, document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL); if (!newDoc->isOk()) { - err = newDoc->getErrorCode(); - delete newDoc; - if (err == errEncrypted) { - g_set_error (error, POPPLER_ERROR, - POPPLER_ERROR_ENCRYPTED, - "Document is encrypted."); - } else { - g_set_error (error, G_FILE_ERROR, - G_FILE_ERROR_FAILED, - "Failed to load document from data (error %d)'\n", - err); + switch (newDoc->getErrorCode()) + { + case errOpenFile: + g_set_error (error, POPPLER_ERROR, + POPPLER_ERROR_OPEN_FILE, + "Failed to open the PDF file"); + break; + case errBadCatalog: + g_set_error (error, POPPLER_ERROR, + POPPLER_ERROR_BAD_CATALOG, + "Failed to read the document catalog"); + break; + case errDamaged: + g_set_error (error, POPPLER_ERROR, + POPPLER_ERROR_DAMAGED, + "PDF document is damaged"); + break; + case errEncrypted: + g_set_error (error, POPPLER_ERROR, + POPPLER_ERROR_ENCRYPTED, + "Document is encrypted"); + break; + default: + g_set_error (error, POPPLER_ERROR, + POPPLER_ERROR_INVALID, + "Failed to load document"); } - + + delete newDoc; return NULL; } diff --git a/glib/poppler.h b/glib/poppler.h index 5f3eaa8c..88a330c5 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -30,7 +30,10 @@ GQuark poppler_error_quark (void); typedef enum { POPPLER_ERROR_INVALID, - POPPLER_ERROR_ENCRYPTED + POPPLER_ERROR_ENCRYPTED, + POPPLER_ERROR_OPEN_FILE, + POPPLER_ERROR_BAD_CATALOG, + POPPLER_ERROR_DAMAGED } PopplerError; typedef enum |