Anonymous avatar Anonymous committed 8bcfd56

Unified error handling by Petr Pajas
Log:
PR:

Comments (0)

Files changed (1)

         xmlDocPtr real_doc;
         HV* real_obj = (HV *)SvRV(self);
         SV** item    = NULL;
+        int recover;
     CODE:
         ptr = SvPV(string, len);
         if (len == 0) {
         LibXML_cleanup_parser();        
 
         sv_2mortal(LibXML_error);
-        
-        if (!real_doc) {
+
+        if (real_doc == NULL) {
             LibXML_croak_error();
             XSRETURN_UNDEF;
         }
         else {
             STRLEN n_a;
-            SV * newURI = newSVpvf("unknown-%12.12d", real_doc);
+            SV * newURI;
+
+            item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+            recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;
+            if (!recover) LibXML_croak_error();
+
+            newURI = newSVpvf("unknown-%12.12d", real_doc);
             real_doc->URL = xmlStrdup((const xmlChar*)SvPV(newURI, n_a));
             SvREFCNT_dec(newURI);
 
         xmlDocPtr real_doc;
         HV* real_obj = (HV *)SvRV(self);
         SV** item    = NULL;
+        int recover;
     CODE:        
         LibXML_init_parser(self);
         real_doc = LibXML_parse_html_stream(self, fh);
         
         sv_2mortal(LibXML_error);
         
-        LibXML_croak_error();
-
-        if (real_doc == NULL ) {
-            croak("something went wrong");
-        }
+
+        if (real_doc == NULL) {
+            LibXML_croak_error();
+            XSRETURN_UNDEF;
+        } 
         else {
             STRLEN n_a;
-            SV * newURI = newSVpvf("unknown-%12.12d", real_doc);
+            SV * newURI;
+
+            item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+            recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;            
+            if (!recover) LibXML_croak_error();
+
+            newURI = newSVpvf("unknown-%12.12d", real_doc);
             real_doc->URL = xmlStrdup((const xmlChar*)SvPV(newURI, n_a));
             SvREFCNT_dec(newURI);
             item = hv_fetch( real_obj, "XML_LIBXML_GDOME", 16, 0 );
         const char * filename
     PREINIT:
         STRLEN len;
-        xmlDocPtr real_doc;
+        xmlDocPtr real_doc = NULL;
         HV* real_obj = (HV *)SvRV(self);
         SV** item    = NULL;
+        int recover;
     CODE:
         LibXML_init_parser(self);
         real_doc = htmlParseFile((char*)filename, NULL);
 
         sv_2mortal(LibXML_error);
 
-        LibXML_croak_error();        
-
-        if (!real_doc) {
-            croak( "no document parsed!" );
-        }
+        if (real_doc == NULL) {
+            LibXML_croak_error();
+            XSRETURN_UNDEF;
+        }
+
+        item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+        recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;
+        if (!recover) LibXML_croak_error();
 
         item = hv_fetch( real_obj, "XML_LIBXML_GDOME", 16, 0 );
 
         SV** item    = NULL;
         STRLEN n_a;
         SV * newURI;
+        int recover;
     CODE:
         LibXML_error = NEWSV(0, 512);
         sv_setpvn(LibXML_error, "", 0);
         LibXML_cleanup_parser();
         
         sv_2mortal(LibXML_error);
-
-        LibXML_croak_error();
         
         if (real_doc == NULL) {
-            croak("no document parsed!");
-        }
+            LibXML_croak_error();
+            XSRETURN_UNDEF;
+        }
+
+        item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+        recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;
+        if (!recover) LibXML_croak_error();
 
         newURI = newSVpvf("unknown-%12.12d", real_doc);
         real_doc->URL = xmlStrdup((const xmlChar*)SvPV(newURI, n_a));
         SV** item    = NULL;
         STRLEN n_a;
         SV * newURI;
+        int recover;
     CODE:
         ptr = SvPV(string, len);
         if (len == 0) {
 
         sv_2mortal(LibXML_error);
 
-        LibXML_croak_error();
-        
-        if (!real_doc) {
-            croak("no document parsed!");
+        if (real_doc == NULL) {
+            LibXML_croak_error();
             XSRETURN_UNDEF;
         }
 
+        item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+        recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;
+        if (!recover) LibXML_croak_error();
+
         newURI = newSVpvf("unknown-%12.12d", real_doc);
         real_doc->URL = xmlStrdup((const xmlChar*)SvPV(newURI, n_a));
         SvREFCNT_dec(newURI);
         xmlDocPtr real_doc;
         HV* real_obj = (HV *)SvRV(self);
         SV** item    = NULL;
+        int recover;
     CODE:
         LibXML_init_parser(self);
         real_doc = (xmlDocPtr) docbParseFile(filename,
 
         sv_2mortal(LibXML_error);
         
-        LibXML_croak_error();
-
-        if (!real_doc) {
-            croak( "no document parsed!" );
+        if (real_doc == NULL) {
+            LibXML_croak_error();
             XSRETURN_UNDEF;
         }
         else {
+            item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
+            recover = ( item != NULL && SvTRUE( *item ) ) ? 1 : 0;
+            if (!recover) LibXML_croak_error();
+            
             item = hv_fetch( real_obj, "XML_LIBXML_GDOME", 16, 0 );
 
             if ( item != NULL && SvTRUE(*item) ) {  
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.