From 4c3522b8e357a4079a8f0f6de84b7312020540dd Mon Sep 17 00:00:00 2001 From: Andrew Walker Date: Wed, 5 Jun 2013 14:30:57 -0400 Subject: [PATCH] dom: Stop serialize from always reporting an error The serialize function has an optional exception argument to catch errors. One of our checks comes from normalising the document and (at this point) this should only see namespace errors. If not, we throw an internal error. However, the check forgot that getException returns 0 if we are not in an exception and turned the no exception case into an internal error. This is fixed by checking if we are in an exceptional state before checking the error code. --- dom/m_dom_utils.f90 | 12 ++++++++---- dom/m_dom_utils.m4 | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dom/m_dom_utils.f90 b/dom/m_dom_utils.f90 index f0e443f2..1234c48a 100644 --- a/dom/m_dom_utils.f90 +++ b/dom/m_dom_utils.f90 @@ -140,8 +140,11 @@ subroutine serialize(startNode, name, ex) call normalizeDocument(startNode, ex) if (present(ex)) then ! Only possible error should be namespace error ... - if (getExceptionCode(ex)/=NAMESPACE_ERR) then - if (getFoX_checks().or.FoX_INTERNAL_ERROR<200) then + ! but we should avoid turning an error of 0 into + ! an internal error! + if (inException(ex)) then + if (getExceptionCode(ex)/=NAMESPACE_ERR) then + if (getFoX_checks().or.FoX_INTERNAL_ERROR<200) then call throw_exception(FoX_INTERNAL_ERROR, "serialize", ex) if (present(ex)) then if (inException(ex)) then @@ -150,8 +153,8 @@ subroutine serialize(startNode, name, ex) endif endif - else - if (getFoX_checks().or.SERIALIZE_ERR<200) then + else + if (getFoX_checks().or.SERIALIZE_ERR<200) then call throw_exception(SERIALIZE_ERR, "serialize", ex) if (present(ex)) then if (inException(ex)) then @@ -160,6 +163,7 @@ subroutine serialize(startNode, name, ex) endif endif + endif endif endif else diff --git a/dom/m_dom_utils.m4 b/dom/m_dom_utils.m4 index 0a6800af..b4c9d473 100644 --- a/dom/m_dom_utils.m4 +++ b/dom/m_dom_utils.m4 @@ -128,10 +128,14 @@ contains call normalizeDocument(startNode, ex) if (present(ex)) then ! Only possible error should be namespace error ... - if (getExceptionCode(ex)/=NAMESPACE_ERR) then - TOHW_m_dom_throw_error(FoX_INTERNAL_ERROR) - else - TOHW_m_dom_throw_error(SERIALIZE_ERR) + ! but we should avoid turning an error of 0 into + ! an internal error! + if (inException(ex)) then + if (getExceptionCode(ex)/=NAMESPACE_ERR) then + TOHW_m_dom_throw_error(FoX_INTERNAL_ERROR) + else + TOHW_m_dom_throw_error(SERIALIZE_ERR) + endif endif endif else