← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-1111786 into lp:zorba

 

Paul J. Lucas has proposed merging lp:~zorba-coders/zorba/bug-1111786 into lp:zorba.

Commit message:
Added $zerr:data-module, $zerr:data-line-number, and $zerr:data-column-number.

Requested reviews:
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1111786 in Zorba: "xml/json parse error location in catch clause"
  https://bugs.launchpad.net/zorba/+bug/1111786

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1111786/+merge/147020

Added $zerr:data-module, $zerr:data-line-number, and $zerr:data-column-number.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1111786/+merge/147020
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-02-03 17:44:39 +0000
+++ ChangeLog	2013-02-07 04:33:25 +0000
@@ -16,6 +16,7 @@
 
 Bug Fixes/Other Changes:
   * Fixed bug #1095889 (Improve error message for xml-parsing error).
+  * Fixed bug #1111786 (xml/json parse error location in catch clause).
   * NaN items are considered equal to each other during grouping
   * Fixed bug #855481 (Too small time types on Windows).
 

=== modified file 'include/zorba/internal/diagnostic.h'
--- include/zorba/internal/diagnostic.h	2013-01-24 04:23:25 +0000
+++ include/zorba/internal/diagnostic.h	2013-02-07 04:33:25 +0000
@@ -200,10 +200,34 @@
   line_type line_end_;
   column_type column_end_;
 
+  friend bool operator==( location const&, location const& );
+
   // for plan serialization
   friend void serialization::operator&( serialization::Archiver&, location& );
 };
 
+/**
+ * \internal
+ * Compares two locations for equality.
+ *
+ * @param i The first location.
+ * @param j The second location.
+ * @return Returns \c true only if the two locations are equal.
+ */
+bool operator==( location const &i, location const &j );
+
+/**
+ * \internal
+ * Compares two locations for inequality.
+ *
+ * @param i The first location.
+ * @param j The second location.
+ * @return Returns \c true only if the two locations are not equal.
+ */
+inline bool operator!=( location const &i, location const &j ) {
+  return !(i == j);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 /**

=== modified file 'include/zorba/xquery_exception.h'
--- include/zorba/xquery_exception.h	2012-12-20 19:37:19 +0000
+++ include/zorba/xquery_exception.h	2013-02-07 04:33:25 +0000
@@ -138,6 +138,77 @@
     return source_loc_.column_end();
   }
 
+  ////////// data file/line location //////////////////////////////////////////
+
+  /**
+   * Checks whether the XQuery data location has been set.
+   *
+   * @return Returns \c true only if the data location has been set.
+   */
+  bool has_data() const throw() {
+    return data_loc_;
+  }
+
+  /**
+   * Sets the XQuery source-code data URI name, line, and column numbers.
+   *
+   * @param uri The source-code data URI name.  Must not be null.
+   * @param line The source-code data URI line number.
+   * @param column The source-code data URI column number.
+   * @param line_end The source-code data URI end line number.
+   * @param column_end The source-code data URI end column number.
+   */
+  void set_data( char const *uri,
+                 line_type line,
+                 column_type column = 0,
+                 line_type line_end = 0,
+                 column_type column_end = 0 );
+
+  /**
+   * Gets the data URI containing the error.
+   *
+   * @return Returns said URI or the empty string if unset.
+   */
+  char const* data_uri() const throw() {
+    return data_loc_.file();
+  }
+
+  /**
+   * Gets the data line number containing the error.
+   *
+   * @return Returns said line number or 0 if unset.
+   */
+  line_type data_line() const throw() {
+    return data_loc_.line();
+  }
+
+  /**
+   * Gets the data column number containing the error.
+   *
+   * @return Returns said column number or 0 if unset.
+   */
+  column_type data_column() const throw() {
+    return data_loc_.column();
+  }
+
+  /**
+   * Gets the data end line number containing the error.
+   *
+   * @return Returns said line number or 0 if unset.
+   */
+  line_type data_line_end() const throw() {
+    return data_loc_.line_end();
+  }
+
+  /**
+   * Gets the data end column number containing the error.
+   *
+   * @return Returns said column number or 0 if unset.
+   */
+  column_type data_column_end() const throw() {
+    return data_loc_.column_end();
+  }
+
   ////////// "applied at" file/line location //////////////////////////////////
 
   /**
@@ -287,6 +358,7 @@
                    line_type raise_line, char const *message );
 
   location source_loc_;
+  location data_loc_;
   location applied_loc_;
   XQueryStackTrace query_trace_;
 
@@ -305,6 +377,9 @@
   friend void set_applied( ZorbaException&, char const*, line_type, column_type,
                            line_type, column_type, bool );
 
+  friend void set_data( ZorbaException&, char const*, line_type, column_type,
+                        line_type, column_type, bool );
+
   friend void set_source( ZorbaException&, char const*, line_type, column_type,
                           line_type, column_type, bool );
 

=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2013-01-11 22:58:12 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2013-02-07 04:33:25 +0000
@@ -2078,6 +2078,15 @@
       case catch_clause::err_column_no:
         rcc.theVars[TryCatchIterator::CatchClause::err_column_no] = *vec;
         break;
+      case catch_clause::zerr_data_module:
+        rcc.theVars[TryCatchIterator::CatchClause::zerr_data_module] = *vec;
+        break;
+      case catch_clause::zerr_data_line_no:
+        rcc.theVars[TryCatchIterator::CatchClause::zerr_data_line_no] = *vec;
+        break;
+      case catch_clause::zerr_data_column_no:
+        rcc.theVars[TryCatchIterator::CatchClause::zerr_data_column_no] = *vec;
+        break;
       case catch_clause::zerr_stack_trace:
         rcc.theVars[TryCatchIterator::CatchClause::zerr_stack_trace] = *vec;
         break;

=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h	2013-01-11 22:58:12 +0000
+++ src/compiler/expression/expr.h	2013-02-07 04:33:25 +0000
@@ -949,6 +949,9 @@
     err_module,
     err_line_no,
     err_column_no,
+    zerr_data_module,
+    zerr_data_line_no,
+    zerr_data_column_no,
     zerr_stack_trace
   };
 

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2013-01-29 06:01:31 +0000
+++ src/compiler/translator/translator.cpp	2013-02-07 04:33:25 +0000
@@ -7817,7 +7817,8 @@
 
   push_scope();
 
-  store::Item_t lCode, lDesc, lValue, lModule, lLineNo, lColumnNo, lStackTrace;
+  store::Item_t lCode, lDesc, lValue, lModule, lLineNo, lColumnNo,
+                lDataModule, lDataLineNo, lDataColumnNo, lStackTrace;
 
   GENV_ITEMFACTORY->createQName(lCode, XQUERY_ERR_NS, "", "code");
   GENV_ITEMFACTORY->createQName(lDesc, XQUERY_ERR_NS, "", "description");
@@ -7825,6 +7826,12 @@
   GENV_ITEMFACTORY->createQName(lModule, XQUERY_ERR_NS, "", "module");
   GENV_ITEMFACTORY->createQName(lLineNo, XQUERY_ERR_NS, "", "line-number");
   GENV_ITEMFACTORY->createQName(lColumnNo, XQUERY_ERR_NS, "", "column-number");
+  GENV_ITEMFACTORY->createQName(lColumnNo, XQUERY_ERR_NS, "", "data-uri");
+  GENV_ITEMFACTORY->createQName(lColumnNo, XQUERY_ERR_NS, "", "data-line-number");
+  GENV_ITEMFACTORY->createQName(lColumnNo, XQUERY_ERR_NS, "", "data-column-number");
+  GENV_ITEMFACTORY->createQName(lDataModule, ZORBA_ERR_NS, "", "data-module");
+  GENV_ITEMFACTORY->createQName(lDataLineNo, ZORBA_ERR_NS, "", "data-line-number");
+  GENV_ITEMFACTORY->createQName(lDataColumnNo, ZORBA_ERR_NS, "", "data-column-number");
   GENV_ITEMFACTORY->createQName(lStackTrace, ZORBA_ERR_NS, "", "stack-trace");
 
   cc->add_var(catch_clause::err_code,
@@ -7845,6 +7852,15 @@
   cc->add_var(catch_clause::err_column_no,
       bind_var(loc, lColumnNo, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
 
+  cc->add_var(catch_clause::zerr_data_module,
+      bind_var(loc, lDataModule, var_expr::catch_var, theRTM.STRING_TYPE_QUESTION));
+
+  cc->add_var(catch_clause::zerr_data_line_no,
+      bind_var(loc, lDataLineNo, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
+
+  cc->add_var(catch_clause::zerr_data_column_no,
+      bind_var(loc, lDataColumnNo, var_expr::catch_var, theRTM.INTEGER_TYPE_QUESTION));
+
   cc->add_var(catch_clause::zerr_stack_trace,
       bind_var(loc, lStackTrace, var_expr::catch_var, theRTM.ITEM_TYPE_QUESTION));
 

=== modified file 'src/diagnostics/diagnostic.cpp'
--- src/diagnostics/diagnostic.cpp	2013-01-24 05:48:07 +0000
+++ src/diagnostics/diagnostic.cpp	2013-02-07 04:33:25 +0000
@@ -176,6 +176,15 @@
 namespace diagnostic {
 
 location const location::empty;
+
+bool operator==( location const &i, location const &j ) {
+  return i.file_       == j.file_
+      && i.line_       == j.line_
+      && i.column_     == j.column_
+      && i.line_end_   == j.line_end_
+      && i.column_end_ == j.column_end_;
+}
+
 parameters const parameters::empty;
 
 #define case_123456789 \

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2013-02-03 19:01:15 +0000
+++ src/diagnostics/diagnostic_en.xml	2013-02-07 04:33:25 +0000
@@ -3447,6 +3447,10 @@
       <value>valid values are: yes, no, omit</value>
     </entry>
 
+    <entry key="InData">
+      <value>in data</value>
+    </entry>
+
     <entry key="IncompleteKeyInIndexBuild">
       <value>incomplete key during index build</value>
     </entry>

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2013-02-03 19:01:15 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2013-02-07 04:33:25 +0000
@@ -634,6 +634,7 @@
   { "~GoodValuesAreXMLEtc", "valid values are: xml, html, xhtml, text, binary, json, jsoniq" },
   { "~GoodValuesAreYesNo", "valid values are: yes, no" },
   { "~GoodValuesAreYesNoOmit", "valid values are: yes, no, omit" },
+  { "~InData", "in data" },
   { "~IncompleteKeyInIndexBuild", "incomplete key during index build" },
   { "~IncompleteKeyInIndexRefresh", "incomplete key during index refresh" },
   { "~JNDY0021_IllegalCharacter_2", "'$2': illegal JSON character" },

=== modified file 'src/diagnostics/pregenerated/dict_zed_keys.h'
--- src/diagnostics/pregenerated/dict_zed_keys.h	2013-02-03 19:01:15 +0000
+++ src/diagnostics/pregenerated/dict_zed_keys.h	2013-02-07 04:33:25 +0000
@@ -187,6 +187,7 @@
 #define ZED_GoodValuesAreXMLEtc "~GoodValuesAreXMLEtc"
 #define ZED_GoodValuesAreYesNo "~GoodValuesAreYesNo"
 #define ZED_GoodValuesAreYesNoOmit "~GoodValuesAreYesNoOmit"
+#define ZED_InData "~InData"
 #define ZED_IncompleteKeyInIndexBuild "~IncompleteKeyInIndexBuild"
 #define ZED_IncompleteKeyInIndexRefresh "~IncompleteKeyInIndexRefresh"
 #define ZED_LibModVersionMismatch_3 "~LibModVersionMismatch_3"

=== modified file 'src/diagnostics/xquery_exception.cpp'
--- src/diagnostics/xquery_exception.cpp	2013-02-07 03:15:48 +0000
+++ src/diagnostics/xquery_exception.cpp	2013-02-07 04:33:25 +0000
@@ -58,6 +58,7 @@
 XQueryException::XQueryException( XQueryException const &from ) :
   ZorbaException( from ),
   source_loc_( from.source_loc_ ),
+  data_loc_( from.data_loc_ ),
   applied_loc_( from.applied_loc_ ),
   query_trace_( from.query_trace_ )
 {
@@ -84,6 +85,7 @@
   if ( &from != this ) {
     ZorbaException::operator=( from );
     source_loc_  = from.source_loc_;
+    data_loc_    = from.data_loc_;
     applied_loc_ = from.applied_loc_;
     query_trace_ = from.query_trace_;
   }
@@ -109,6 +111,16 @@
   applied_loc_.set( uri, line, col, line_end, col_end );
 }
 
+void XQueryException::set_data( char const *uri,
+                                line_type line,
+                                column_type col,
+                                line_type line_end,
+                                column_type col_end ) {
+  if ( !uri || !*uri )
+    uri = source_loc_.file();
+  data_loc_.set( uri, line, col, line_end, col_end );
+}
+
 void XQueryException::set_source( char const *uri,
                                   line_type line,
                                   column_type col,
@@ -150,6 +162,16 @@
 #endif
       o << "/>" << if_nl; // <location ...
 
+      if ( has_data() ) {
+        o << indent << "<data-location";
+        if ( data_uri() && ::strcmp( data_uri(), source_uri() ) != 0 )
+          print_uri( o, applied_uri() );
+        o << " line=\"" << data_line() << '"';
+        if ( data_column() )
+          o << " column=\"" << data_column() << '"';
+        o << "/>" << if_nl; // <data-location ...
+      }
+
       if ( has_applied() ) {
         o << indent << "<applied-at";
         if ( applied_uri() && ::strcmp( applied_uri(), source_uri() ) != 0 )
@@ -172,6 +194,18 @@
       if ( source_column() )
         o << "," << source_column();
 
+      if ( has_data() && data_loc_ != source_loc_ ) {
+        o << " (" << diagnostic::dict::lookup( ZED( InData ) ) << ' ';
+        if ( data_uri() && ::strcmp( data_uri(), source_uri() ) != 0 ) {
+          if ( print_uri( o, data_uri() ) )
+            o << ':';
+        }
+        o << data_line();
+        if ( data_column() )
+          o << ',' << data_column();
+        o << ')';
+      }
+
       if ( has_applied() ) {
         o << " (" << diagnostic::dict::lookup( ZED( AppliedAt ) ) << ' ';
         if ( applied_uri() && ::strcmp( applied_uri(), source_uri() ) != 0 ) {
@@ -341,6 +375,24 @@
   }
 }
 
+void set_data( ZorbaException &ze, char const *file,
+               XQueryException::line_type line,
+               XQueryException::column_type col,
+               XQueryException::line_type line_end,
+               XQueryException::column_type col_end,
+               bool overwrite ) {
+  if ( XQueryException *const xe = dynamic_cast<XQueryException*>( &ze ) ) {
+    if ( !xe->has_data() || overwrite )
+      xe->set_data( file, line, col, line_end, col_end );
+  } else {
+    XQueryException new_xe(
+      ze.diagnostic(), ze.raise_file(), ze.raise_line(), ze.what()
+    );
+    new_xe.set_data( file, line, col, line_end, col_end );
+    throw new_xe;
+  }
+}
+
 void set_source( ZorbaException &ze, char const *file,
                  XQueryException::line_type line,
                  XQueryException::column_type col,

=== modified file 'src/diagnostics/xquery_exception.h'
--- src/diagnostics/xquery_exception.h	2013-02-05 04:53:32 +0000
+++ src/diagnostics/xquery_exception.h	2013-02-07 04:33:25 +0000
@@ -232,6 +232,112 @@
   }
 }
 
+////////// XQuery diagnostic data location ////////////////////////////////////
+
+/**
+ * Sets the data location of the given ZorbaException but only if it's actually
+ * an XQueryException.  If it's actually a ZorbaException, constructs a new
+ * XQueryException (copying the information from the ZorbaException) and throws
+ * it.
+ *
+ * @param ze The ZorbaException to set the location of.
+ * @param file The data file name.
+ * @param line The line number.
+ * @param col The column number.
+ * @param line_end The end line number.
+ * @param col_end The end column number.
+ * @param overwrite If \c false, sets the location only if the exception
+ * doesn't already have one; if \c true, always sets the location even if the
+ * exception already has one.
+ */
+void set_data( ZorbaException &ze, char const *file,
+               XQueryException::line_type line,
+               XQueryException::column_type col,
+               XQueryException::line_type line_end,
+               XQueryException::column_type col_end,
+               bool overwrite = true );
+
+/**
+ * Sets the data location of the given ZorbaException but only if it's actually
+ * an XQueryException.  If it's actually a ZorbaException, constructs a new
+ * XQueryException (copying the information from the ZorbaException) and throws
+ * it.
+ *
+ * @tparam StringType The \a file string type.
+ * @param ze The ZorbaException to set the location of.
+ * @param file The data file name.
+ * @param line The line number.
+ * @param col The column number.
+ * @param line_end The end line number.
+ * @param col_end The end column number.
+ * @param overwrite If \c false, sets the location only if the exception
+ * doesn't already have one; if \c true, always sets the location even if the
+ * exception already has one.
+ */
+template<class StringType> inline
+void set_data( ZorbaException &ze, StringType const &file,
+               XQueryException::line_type line,
+               XQueryException::column_type col,
+               XQueryException::line_type line_end,
+               XQueryException::column_type col_end,
+               bool overwrite = true ) {
+  set_data( ze, file.c_str(), line, col, line_end, col_end, overwrite );
+}
+
+/**
+ * Sets the data location of the given ZorbaException but only if it's actually
+ * an XQueryException.  If it's actually a ZorbaException, constructs a new
+ * XQueryException (copying the information from the ZorbaException) and throws
+ * it.
+ *
+ * @param ze The ZorbaException to set the location of.
+ * @param loc The query location.
+ * @param overwrite If \c false, sets the location only if the exception
+ * doesn't already have one; if \c true, always sets the location even if the
+ * exception already has one.
+ */
+inline void set_data( ZorbaException &ze, QueryLoc const &loc,
+                      bool overwrite = true ) {
+  set_data(
+    ze,
+    loc.getFilename(),
+    loc.getLineBegin(),
+    loc.getColumnBegin(),
+    loc.getLineEnd(),
+    loc.getColumnEnd(),
+    overwrite
+  );
+}
+
+/**
+ * Sets the data location of the given ZorbaException but only if it's actually
+ * an XQueryException.  If it's actually a ZorbaException, constructs a new
+ * XQueryException (copying the information from the ZorbaException) and throws
+ * it.
+ *
+ * @param to The ZorbaException to set the location of.
+ * @param from The ZorbaException to get the location from but only if it's
+ * actually an XQueryException.
+ * @param overwrite If \c false, sets the location only if the exception
+ * doesn't already have one; if \c true, always sets the location even if the
+ * exception already has one.
+ */
+inline void set_data( ZorbaException &to, ZorbaException const &from,
+                      bool overwrite = true ) {
+  if ( XQueryException const *const xe =
+        dynamic_cast<XQueryException const*>( &from ) ) {
+    set_data(
+      to,
+      xe->data_uri(),
+      xe->data_line(),
+      xe->data_column(),
+      xe->data_line_end(),
+      xe->data_column_end(),
+      overwrite
+    );
+  }
+}
+
 ////////// XQuery diagnostic "applied at" location ////////////////////////////
 
 /**

=== modified file 'src/runtime/core/trycatch.cpp'
--- src/runtime/core/trycatch.cpp	2012-10-08 12:09:36 +0000
+++ src/runtime/core/trycatch.cpp	2013-02-07 04:33:25 +0000
@@ -498,6 +498,94 @@
         }
       break;
       }
+
+      case CatchClause::zerr_data_module:
+      {
+        LetVarConstIter lErrorDataModuleVarIter = lIter->second.begin();
+        LetVarConstIter const lErrorDataModuleVarIterEnd = lIter->second.end();
+
+        for ( ; lErrorDataModuleVarIter != lErrorDataModuleVarIterEnd;
+              ++lErrorDataModuleVarIter )
+        {
+          store::Iterator_t lErrorDataModuleIter;
+
+          XQueryException const *const xe =
+            dynamic_cast<XQueryException const*>( &e );
+	        if ( xe && xe->has_data() ) {
+            store::Item_t lErrorDataModuleItem;
+            zstring uri( xe->data_uri() );
+            GENV_ITEMFACTORY->createString( lErrorDataModuleItem, uri );
+            lErrorDataModuleIter = new ItemIterator(lErrorDataModuleItem);
+	        }
+          else
+          {
+            lErrorDataModuleIter = new ItemIterator();
+          }
+          lErrorDataModuleIter->open();
+          state->theErrorIters.push_back(lErrorDataModuleIter);
+          (*lErrorDataModuleVarIter)->bind(lErrorDataModuleIter, planState);
+        }
+        break;
+      }
+
+      case CatchClause::zerr_data_line_no:
+      {
+        LetVarConstIter lErrorDataLineVarIter = lIter->second.begin();
+        LetVarConstIter const lErrorDataLineVarIterEnd = lIter->second.end();
+
+        for ( ; lErrorDataLineVarIter != lErrorDataLineVarIterEnd;
+              ++lErrorDataLineVarIter )
+        {
+          store::Iterator_t lErrorDataLineIter;
+
+          XQueryException const *const xe =
+            dynamic_cast<XQueryException const*>( &e );
+	        if ( xe && xe->has_data() ) {
+            store::Item_t lErrorDataLineItem;
+            GENV_ITEMFACTORY->createInteger(
+                lErrorDataLineItem, xs_integer(xe->data_line()));
+            lErrorDataLineIter = new ItemIterator(lErrorDataLineItem);
+	        }
+          else
+          {
+            lErrorDataLineIter = new ItemIterator();
+          }
+          lErrorDataLineIter->open();
+          state->theErrorIters.push_back(lErrorDataLineIter);
+          (*lErrorDataLineVarIter)->bind(lErrorDataLineIter, planState);
+        }
+        break;
+      }
+
+      case CatchClause::zerr_data_column_no:
+      {
+        LetVarConstIter lErrorDataColumnVarIter = lIter->second.begin();
+        LetVarConstIter const lErrorDataColumnVarIterEnd = lIter->second.end();
+
+        for ( ; lErrorDataColumnVarIter != lErrorDataColumnVarIterEnd;
+              ++lErrorDataColumnVarIter )
+        {
+          store::Iterator_t lErrorDataColumnIter;
+
+          XQueryException const *const xe =
+            dynamic_cast<XQueryException const*>( &e );
+	        if ( xe && xe->has_data() ) {
+            store::Item_t lErrorDataColumnItem;
+            GENV_ITEMFACTORY->createInteger(
+                lErrorDataColumnItem, xs_integer(xe->data_column()));
+            lErrorDataColumnIter = new ItemIterator(lErrorDataColumnItem);
+	        }
+          else
+          {
+            lErrorDataColumnIter = new ItemIterator();
+          }
+          lErrorDataColumnIter->open();
+          state->theErrorIters.push_back(lErrorDataColumnIter);
+          (*lErrorDataColumnVarIter)->bind(lErrorDataColumnIter, planState);
+        }
+        break;
+      }
+
       case CatchClause::zerr_stack_trace:
       {
         LetVarConstIter lStackTraceVarIter = lIter->second.begin();

=== modified file 'src/runtime/core/trycatch.h'
--- src/runtime/core/trycatch.h	2012-09-19 21:16:15 +0000
+++ src/runtime/core/trycatch.h	2013-02-07 04:33:25 +0000
@@ -61,6 +61,9 @@
       err_module,
       err_line_no,
       err_column_no,
+      zerr_data_module,
+      zerr_data_line_no,
+      zerr_data_column_no,
       zerr_stack_trace
     };
 

=== modified file 'src/runtime/json/common.cpp'
--- src/runtime/json/common.cpp	2011-12-28 05:41:00 +0000
+++ src/runtime/json/common.cpp	2013-02-07 04:33:25 +0000
@@ -15,7 +15,10 @@
  */
 #include "stdafx.h"
 
+#include <zorba/xquery_exception.h>
+
 #include "store/api/iterator.h"
+#include "util/json_parser.h"
 
 #include "common.h"
 
@@ -42,6 +45,13 @@
   return found;
 }
 
+void set_data( XQueryException *xe, json::exception const &je ) {
+  json::location const &loc( je.get_loc() );
+  xe->set_data(
+    loc.file(), loc.line(), loc.column(), loc.line_end(), loc.column_end()
+  );
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #if ZORBA_DEBUG_JSON

=== modified file 'src/runtime/json/common.h'
--- src/runtime/json/common.h	2013-02-01 06:03:17 +0000
+++ src/runtime/json/common.h	2013-02-07 04:33:25 +0000
@@ -30,6 +30,9 @@
 
 namespace zorba {
 
+class XQueryException;
+namespace json { class exception; }
+
 ///////////////////////////////////////////////////////////////////////////////
 
 typedef std::stack<store::Item*> item_stack_type;
@@ -56,6 +59,10 @@
 bool get_attribute_value( store::Item_t const &element, char const *att_name,
                           zstring *att_value );
 
+void set_data( XQueryException*, json::exception const& );
+
+typedef std::ostream& (*std_omanip_type)(std::ostream&);
+
 ///////////////////////////////////////////////////////////////////////////////
 
 #define IN_STATE(S) ztd::top_stack_equals( state_stack, (S) )

=== modified file 'src/runtime/json/json_impl.cpp'
--- src/runtime/json/json_impl.cpp	2012-11-29 05:00:43 +0000
+++ src/runtime/json/json_impl.cpp	2013-02-07 04:33:25 +0000
@@ -103,50 +103,78 @@
       ZORBA_ASSERT( false );
   }
   catch ( json::illegal_character const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0001_ILLEGAL_CHARACTER,
-      ERROR_PARAMS( ascii::printable_char( e.get_char() ) ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0001_ILLEGAL_CHARACTER,
+        ERROR_PARAMS( ascii::printable_char( e.get_char() ) ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_codepoint const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0002_ILLEGAL_CODEPOINT,
-      ERROR_PARAMS( e.get_codepoint() ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0002_ILLEGAL_CODEPOINT,
+        ERROR_PARAMS( e.get_codepoint() ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_escape const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0003_ILLEGAL_ESCAPE,
-      ERROR_PARAMS( e.get_escape() ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0003_ILLEGAL_ESCAPE,
+        ERROR_PARAMS( e.get_escape() ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_literal const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0004_ILLEGAL_LITERAL,
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0004_ILLEGAL_LITERAL,
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_number const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0005_ILLEGAL_NUMBER,
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0005_ILLEGAL_NUMBER,
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::unexpected_token const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0006_UNEXPECTED_TOKEN,
-      ERROR_PARAMS( e.get_token() ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0006_UNEXPECTED_TOKEN,
+        ERROR_PARAMS( e.get_token() ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::unterminated_string const &e ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZJPE0007_UNTERMINATED_STRING,
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        zerr::ZJPE0007_UNTERMINATED_STRING,
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
 
   STACK_PUSH( !!result, state );

=== modified file 'src/runtime/json/json_loader.cpp'
--- src/runtime/json/json_loader.cpp	2012-12-03 18:29:05 +0000
+++ src/runtime/json/json_loader.cpp	2013-02-07 04:33:25 +0000
@@ -31,6 +31,7 @@
 #include "zorbatypes/zstring.h"
 
 // local
+#include "common.h"
 #include "json_loader.h"
 
 using namespace std;
@@ -206,65 +207,93 @@
     return false;
   } // try
   catch ( json::illegal_character const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS(
-        ZED( JNDY0021_IllegalCharacter_2 ),
-        ascii::printable_char( e.get_char() )
-      ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS(
+          ZED( JNDY0021_IllegalCharacter_2 ),
+          ascii::printable_char( e.get_char() )
+        ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_codepoint const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS(
-        ZED( JNDY0021_IllegalCodepoint_2 ),
-        e.get_codepoint()
-      ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS(
+          ZED( JNDY0021_IllegalCodepoint_2 ),
+          e.get_codepoint()
+        ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_escape const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS(
-        ZED( JNDY0021_IllegalEscape_2 ),
-        ascii::printable_char( e.get_escape() )
-      ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS(
+          ZED( JNDY0021_IllegalEscape_2 ),
+          ascii::printable_char( e.get_escape() )
+        ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_literal const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS( ZED( JNDY0021_IllegalLiteral ) ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS( ZED( JNDY0021_IllegalLiteral ) ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::illegal_number const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS( ZED( JNDY0021_IllegalNumber ) ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS( ZED( JNDY0021_IllegalNumber ) ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::unexpected_token const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS(
-        ZED( JNDY0021_UnexpectedToken_2 ),
-        e.get_token()
-      ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS(
+          ZED( JNDY0021_UnexpectedToken_2 ),
+          e.get_token()
+        ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
   catch ( json::unterminated_string const &e ) {
-    throw XQUERY_EXCEPTION(
-      jerr::JNDY0021,
-      ERROR_PARAMS( ZED( JNDY0021_UnterminatedString ) ),
-      ERROR_LOC( e.get_loc() )
+    XQueryException xe(
+      XQUERY_EXCEPTION(
+        jerr::JNDY0021,
+        ERROR_PARAMS( ZED( JNDY0021_UnterminatedString ) ),
+        ERROR_LOC( e.get_loc() )
+      )
     );
+    set_data( &xe, e );
+    throw xe;
   }
 }
 

=== modified file 'src/store/naive/loader_fast.cpp'
--- src/store/naive/loader_fast.cpp	2013-01-21 03:22:59 +0000
+++ src/store/naive/loader_fast.cpp	2013-02-07 04:33:25 +0000
@@ -145,30 +145,32 @@
   XmlLoader *const loader = static_cast<XmlLoader*>( ctx );
   switch ( error->level ) {
     case XML_ERR_ERROR:
-    case XML_ERR_FATAL:
-      loader->theXQueryDiagnostics->add_error(
-        NEW_XQUERY_EXCEPTION(
-          zerr::ZSTR0021_LOADER_PARSING_ERROR,
-          ERROR_PARAMS(
-            error->file, error->line, error->int2 /* column */,
-            libxml_dict_key_4, error_str1_5, error_str2_6, error_str3_7,
-            error_int1_8, error_message_9
-          )
-        )
-      );
-      break;
-    case XML_ERR_WARNING:
-      loader->theXQueryDiagnostics->add_warning(
-        NEW_XQUERY_WARNING(
-          zwarn::ZWST0007_LOADER_PARSING_WARNING,
-          WARN_PARAMS(
-            error->file, error->line, error->int2 /* column */,
-            libxml_dict_key_4, error_str1_5, error_str2_6, error_str3_7,
-            error_int1_8, error_message_9
-          )
-        )
-      );
-      break;
+    case XML_ERR_FATAL: {
+      XQueryException *const xe = NEW_XQUERY_EXCEPTION(
+        zerr::ZSTR0021_LOADER_PARSING_ERROR,
+        ERROR_PARAMS(
+          error->file, error->line, error->int2 /* column */,
+          libxml_dict_key_4, error_str1_5, error_str2_6, error_str3_7,
+          error_int1_8, error_message_9
+        )
+      );
+      xe->set_data( error->file, error->line, error->int2 /* column */ );
+      loader->theXQueryDiagnostics->add_error( xe );
+      break;
+    }
+    case XML_ERR_WARNING: {
+      XQueryWarning *const xw = NEW_XQUERY_WARNING(
+        zwarn::ZWST0007_LOADER_PARSING_WARNING,
+        WARN_PARAMS(
+          error->file, error->line, error->int2 /* column */,
+          libxml_dict_key_4, error_str1_5, error_str2_6, error_str3_7,
+          error_int1_8, error_message_9
+        )
+      );
+      xw->set_data( error->file, error->line, error->int2 /* column */ );
+      loader->theXQueryDiagnostics->add_warning( xw );
+      break;
+    }
     default:
       ZORBA_ASSERT( false );
   } // switch


Follow ups