How to debug "An unexpected error has occurred: Unspecified Failure"

Hi everbody,

I'm new to DXL development and I ran into a major problem. I developed report scripts to extract several operating figures. Problem is that the script dies with the following error message while processing a specific formal module. Another formal module with minor differences can be processed with no error.

[progress] Executing /DXLSupportScripts/src/reports/SVSOperatingFigures.dxl
-R-F- DXL: <reports/collectVVOperatingFigures.inc:77> internal error, please submit a bug report
Backtrace:
    <reports/collectVVOperatingFigures.inc:175> 
        <reports/collectVVOperatingFigures.inc:306> 
        <reports/collectVVOperatingFigures.inc:405> 
        <Line:200> 
-R-E- DXL: <reports/collectVVOperatingFigures.inc:77> An unexpected error has occurred: Unspecified Failure
 
Backtrace:
        <reports/collectVVOperatingFigures.inc:175> 
        <reports/collectVVOperatingFigures.inc:306> 
        <reports/collectVVOperatingFigures.inc:405> 
        <Line:200> 
-I- DXL: execution halted
[progress] Done.


I'm fully stuck. What I tried so far:

 

  • disabled the problematic function call: removes the error but results of the script are worhtless
  • exchanged the called function with a dummy func within the same DXL script include: error occurrs
  • replace function call with function code: error occurred
  • changed call hierarchy to be almost equal to the working script: error occurred
  • I played with pass by value und reference of problematic functions in case it is a stack problem, but did not help. BTW: is it good to pass an Array by reference?


strings.inc:

 

 

int array_size(
   /*IN*/ Array a)
{
   int size = 0;
   while( !null(get(a, size, 0) ) )
   {
      size++;
   }
   return size;
}
 
void array_push_str(
   /*IN,OUT*/ Array a,
   /*IN*/     string str)
{
   int array_index = array_size(a);
   put(a, str, array_index, 0);
}
 
int str_split(
   /*IN*/ const string& str,
   /*IN*/ const string& separator,
   /*OUT*/ Array& tokens)
{
   if(null tokens)
   {
      return 0;
   }
   
   Buffer buf = create;
   int str_index;
 
   buf = "";
 
   for(str_index = 0; str_index < length(str); str_index++) 
   {
      if( str[str_index:str_index] == separator ) 
      {
         array_push_str(tokens, stringOf(buf));
         buf = "";
      }
      else
      {
         buf += str[str_index:str_index];
      }
    }
    array_push_str(tokens, stringOf(buf));
 
    delete buf;
    return array_size(tokens);
}



collectVVOperatingFigures.inc:



 

 

void parseAndAddProcedureNames(
   /*IN*/ const string& str, 
   /*OUT*/ Array& setOfTestScripts)
{
   //logTraceEnterFunc("parseAndAddProcedureNames(const string&,Array&)");
   
   Array lines = create(1,1);   
   
   int count = str_split(str, NEWLINE, lines);
   
   int i = 0;
   for( i=0; i<count; ++i ) {
      string procname = array_get_str(lines, i);
      procname = str_trim(procname);
      if( 0 < length(procname) && !array_contains_str(setOfTestScripts, procname) )
      {
         //logTrace("array_push_str(setOfTestScripts, '" procname "')");
         array_push_str(setOfTestScripts, procname);
      }
   }
   //logTraceLeaveFunc("parseAndAddProcedureNames(const string&,Array&)");
   delete lines;      
}


For development I'm using the Sodius DXLEditor and currently I have the trial version of the debugger feature but that did not help to solve the issue.

 


KaiK. - Fri Feb 24 08:55:40 EST 2012

Re: How to debug "An unexpected error has occurred: Unspecified Failure"
Mathias Mamsch - Fri Feb 24 10:36:40 EST 2012

Ok the first thing to notice is that in DXL 'const parameter definitions' are completly ignored. They do not seem to disturb either, but I still would not use them (bad experience with doing such stuff. Try "return (void) instead of return" for example. Will work 1000x but fail you with an error the 1001th time.)
 

void func(const string x) { x = "allo"; print x }
func("Hello")

 

The next thing to notice is, that the bug that you are experiencing might not be in the code you posted. When you say that another module processed fine, but one gives you an error, that might mean, that some part of the code does not handle an object or module correctly. The code you have posted however seems to handle only normal string data - if it failed it would probably fail for all of your modules. There is one exception:

 

 

int array_size(Array a)
{
   while( !null(get(a, size, 0) ) )  // This line is fishy!
      ...
}



You definitely need to cast your array value before the null check, otherwise you get a random null function to be used for the null check (e.g. null (real) or null (_m)). If your code is crashing at that line, it would not surprise me.

Other nit picks:

// either make separator a 'char' or use a substring of valid length
if( str[str_index:str_index] == separator ) 
 
// should be:
if( str[str_index:str_index+lSeparator-1] == separator) // don't forget to increase the index accordingly!



Regarding the References & you need to be careful that you will not accidently push a reference to an array/skip list instead of the variable itself. So I would use references only, if you really need to reassign the variable that the function has been called with (and I am not saying 'changing' i am saying 'reassigning'! To change a buffer, you do not need to reassign it. To change string you do!).

Which line is line 77 in collectVVOperatingFigures?

Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: How to debug "An unexpected error has occurred: Unspecified Failure"
KaiK. - Fri Feb 24 11:25:25 EST 2012

Mathias Mamsch - Fri Feb 24 10:36:40 EST 2012

Ok the first thing to notice is that in DXL 'const parameter definitions' are completly ignored. They do not seem to disturb either, but I still would not use them (bad experience with doing such stuff. Try "return (void) instead of return" for example. Will work 1000x but fail you with an error the 1001th time.)
 

void func(const string x) { x = "allo"; print x }
func("Hello")

 

The next thing to notice is, that the bug that you are experiencing might not be in the code you posted. When you say that another module processed fine, but one gives you an error, that might mean, that some part of the code does not handle an object or module correctly. The code you have posted however seems to handle only normal string data - if it failed it would probably fail for all of your modules. There is one exception:

 

 

int array_size(Array a)
{
   while( !null(get(a, size, 0) ) )  // This line is fishy!
      ...
}



You definitely need to cast your array value before the null check, otherwise you get a random null function to be used for the null check (e.g. null (real) or null (_m)). If your code is crashing at that line, it would not surprise me.

Other nit picks:

// either make separator a 'char' or use a substring of valid length
if( str[str_index:str_index] == separator ) 
 
// should be:
if( str[str_index:str_index+lSeparator-1] == separator) // don't forget to increase the index accordingly!



Regarding the References & you need to be careful that you will not accidently push a reference to an array/skip list instead of the variable itself. So I would use references only, if you really need to reassign the variable that the function has been called with (and I am not saying 'changing' i am saying 'reassigning'! To change a buffer, you do not need to reassign it. To change string you do!).

Which line is line 77 in collectVVOperatingFigures?

Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

> Mathias Mamsch wrote:
> Which line is line 77 in collectVVOperatingFigures?

the call of str_split in parseAndAdd...

Re: How to debug "An unexpected error has occurred: Unspecified Failure"
llandale - Fri Feb 24 11:38:01 EST 2012

I echo what Mathias said.

First of all, if you are getting an error here: collectVVOperatingFigures.inc:77, then surely you should be posting that code and telling us which is line 77. Posting the surrounding code (as you did) may help, but not nearly as much.

"const" seems right now to do nothing, but if ever they implement it then it would make no sense to use it in a call parameter, since they are not constants they are variables.

You MUST "caste" retrievals from Skip and from Arrays. ALL your Array "get" command must look like this:
  • (type get(Array, iX-Coord, iY-Coord))
Notice the outside set of parens. In this case:
  • while( !null(string get(a, size, 0) ) )
And of course you are playing with fire if the type of data used in "put" is not exactly the same as in "get".

As for "Arrays", I'm setting into these conventions:
  • Each Column of the Array contains exactly the same type of data; such as 'string' Name or 'Object' handle.
  • There is a Skip list of each Array housing the Index of each value // KEY 'string'; DATA: 'int' iRow
  • There is an Integer variable containing the number of rows and implies where the next row gets inserted.
  • I find it easier to visually the "Array" like a spread sheet; fixed number of columns (X-Coordinate) and variable number of rows (Y-Coordinate). That caused me to switch my parameters, in this case for you:
    • while( !null((string get(a, 0, size)) ) )
  • I also now call my indexing variables either "iCol_xxx" or "iRow_xxx" as it helps me keep them straight; the "iCol_xxx" ones are constants.

Your Array seems to have only one column. Seems to me a Skip list would work better.

array_push_str() should not push a null string.

If 'Separator' is a single character (such as a comma), then your code would be eaiser to read if it was defined as type "char". If its a string, such as ", " then your code doesn't work.

-Louie

Re: How to debug "An unexpected error has occurred: Unspecified Failure"
KaiK. - Wed Feb 29 02:33:38 EST 2012

llandale - Fri Feb 24 11:38:01 EST 2012
I echo what Mathias said.

First of all, if you are getting an error here: collectVVOperatingFigures.inc:77, then surely you should be posting that code and telling us which is line 77. Posting the surrounding code (as you did) may help, but not nearly as much.

"const" seems right now to do nothing, but if ever they implement it then it would make no sense to use it in a call parameter, since they are not constants they are variables.

You MUST "caste" retrievals from Skip and from Arrays. ALL your Array "get" command must look like this:

  • (type get(Array, iX-Coord, iY-Coord))
Notice the outside set of parens. In this case:
  • while( !null(string get(a, size, 0) ) )
And of course you are playing with fire if the type of data used in "put" is not exactly the same as in "get".

As for "Arrays", I'm setting into these conventions:
  • Each Column of the Array contains exactly the same type of data; such as 'string' Name or 'Object' handle.
  • There is a Skip list of each Array housing the Index of each value // KEY 'string'; DATA: 'int' iRow
  • There is an Integer variable containing the number of rows and implies where the next row gets inserted.
  • I find it easier to visually the "Array" like a spread sheet; fixed number of columns (X-Coordinate) and variable number of rows (Y-Coordinate). That caused me to switch my parameters, in this case for you:
    • while( !null((string get(a, 0, size)) ) )
  • I also now call my indexing variables either "iCol_xxx" or "iRow_xxx" as it helps me keep them straight; the "iCol_xxx" ones are constants.

Your Array seems to have only one column. Seems to me a Skip list would work better.

array_push_str() should not push a null string.

If 'Separator' is a single character (such as a comma), then your code would be eaiser to read if it was defined as type "char". If its a string, such as ", " then your code doesn't work.

-Louie

Thanks fot the reply. In the meanwhile I recoded the problematic functions and now the error is avoided but I'm realy frutstrated about not solving the origin of the failure.

Re: How to debug "An unexpected error has occurred: Unspecified Failure"
Mathias Mamsch - Wed Feb 29 03:55:42 EST 2012

KaiK. - Wed Feb 29 02:33:38 EST 2012
Thanks fot the reply. In the meanwhile I recoded the problematic functions and now the error is avoided but I'm realy frutstrated about not solving the origin of the failure.

If the error you posted really occured at the call to split_str then my guess would be that you have a 'double declaration error'. DXL takes double declarations of functions most of the time without errors, but sometimes it will weirdly crash with about the symptoms you describe at totally weird places, when you define a function more than once with the same set of parameters.

In your case the call to split_str is totally harmless und should not be the root of a crash.

There is only one way I know to find the root cause of such problems. First start looking for all other definitions of split_str, NEWLINE, etc. Then comment out the call and see if the error still happens. If so start commenting out code, until the error goes away if necessary engineer the code back to a "Hello World", until the error goes away. You should start by removing any include dependencies. Just comment out all calls to other libraries one by one, and replace the return values of these functions by dummies. As soon as the error goes away, look at what you commented out last. Comment it back in to test, if the error really comes back. Then you start dealing only with this part of the code. Comment everything out in the problematic function and start commenting in code until the error comes back. You can do this until you find the exact line that is problematic. That way I was able to find the root of a lot of strange bugs in DXL.

Maybe that helps, regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS