Can i customrize the error handler in the linq report engine?

Hi team,

I want to customrize the error handler in the linq report engine, how can i do it?

What I want to do:

  1. Collect the errors(tag definition,data format, etc)
  2. Ignore some errors. If there are some errors in building report, collect the errors, ignore the errors and continue the building.
    3.Replace the error tag to anonther text(or node). If there are some errors on building tag1, i want to replace <<[tag1]>> to “ERROR”

@Doraemon

Unfortunately, there is no way to collect all errors while building a report using LINQ Reporting Engine. A template structure can be complex at times, so a single error can make the rest of template content invalid. That is why, the engine stops its execution once it encounters the first error and there is no way to get all errors at once.

By the same reason, there is no way to skip arbitrary errors. However, access to missing members of a data source can be allowed as follows:

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(...);

See Accessing Missing Members of Data Objects for more information.

This can be done using the following code snippet:

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.INLINE_ERROR_MESSAGES);

if (engine.buildReport(...))
{
	// Do something with a successfully built report.
}
else
{
	// Do something with a report containing a template syntax error.
}

See Inlining Syntax Error Messages into Templates for more information. Please note, however, that it relates to the first encountered template syntax error as well.

To combine several options, the bitwise-or operator can be applied as follows:

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS | ReportBuildOptions.INLINE_ERROR_MESSAGES);

@ivan.lyagin
I see. It means that if I want to collect all errors, I should do something like this. Is it correct?


while (!engine.buildReport(doc,...))
{
	// findAndReplce the error
       //collect the error
      //rebuild report with other tag
}

@Doraemon

This may work to some extent, but beware of the following pitfalls if applying this approach:

  1. A template syntax error made by a user can be of any type, not necessary an expected one. Processing of each and every possible error is challenging.
  2. Word “Error” may be a regular part of a template rather than an indication of a syntax error.

@ivan.lyagin
I got it. I will be more cautious about the approach.

What is the structure of the error template tag?Like this?

<<tag_name [expression] –switch1 –switch2 ... # optional_tag_header // optional_comment ERROR! ErrorMessage>>

@Doraemon

An error may appear at any part of a tag - closer to what causes the error. It may appear even outside of a tag, when logic of opening and closing tags is broken, for example.

@ivan.lyagin
I see. The error is equivalent of the error in rendering, not only for the template syntax or format. Is it right?

@Doraemon

As per ReportBuildOptions.INLINE_ERROR_MESSAGES description, the option affects only template syntax errors. For example, division by zero (which may appear while evaluating an expression) is not a syntactic error, but a runtime error, so its processing is not affected by ReportBuildOptions.INLINE_ERROR_MESSAGES.

@ivan.lyagin
I got it. I need to reevaluate the idea.

Thank you for your support. It‘s great.

1 Like