Explorations in Component Interface: Handling Component Interface Errors



This is a continuation of the following posts:

The plan this time is to try to see how well we can handle errors.  I have been having trouble with some of my production programs crashing when I have taken all the necessary steps to trap and handle the error.  So, we’ll see how this goes …

Trying a Single Error

First, let’s change that second parameter in our program to true.  This should trigger the part of our code that set’s the birth state to “XX”.  Assuming everything works the way it should, we should catch the Invalid Value message and write it to the log file.  Then, the program should run to completion showing the Program Completed message from the second step.

Code

Again, see the App Engine test post for instructions on how to run the program.  Then, look in the log file generated by the PeopleCode.  As we would expect, we see the Invalid Value messages:

Code

Then, if you look in the program’s standard out log, you see the message as well.  I think this is a bug in the tools because we did trap the message.  If I tell it to only put the message in the message collection, I should be able to do what I want with the message as far as showing it or hiding it:

Code

Keep in mind that we are specifying the collection only option.  If we had chosen “2” or “3” for the messages mode, I would expect the “Invalid Value” message in the standard out, but we are specifying “1”:

Code

Multiple Updates

Now, lets try multiple updates with a single error at the end:

Code

If you want, you can just copy my lines:

updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, True);

Both logs look just fine:

Output

The key is that it ran to the end of the PeopleCode hence the “End” message, and it ran all the way through Step 2 hence the “Process Complete” message.

Just to be sure, we should try a few different combinations.  Maybe one with the error on the second to last one:

updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, True);
updateCI(&emplid, False);

This didn’t cause any problems for me.  So, let’s try one in the middle:

updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, True);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);

Again, this worked fine for me.  So, I wasn’t able to reproduce my problem that I keep seeing in production.

Triggering an “Error()”

So far, our examples haven’t actually triggered an error within the Save.  Let’s try that.

First, the easiest way I could come up with was to add some code to the SavePreChange of our component.  If you open up the Component Interface from your project, you can right click on the Component on the left hand side.  Then, if you choose “View Definition”, it will open the Component.  Then, you can choose View > PeopleCode and navigate to the SavePreChange.

I added the following PeopleCode to the end of the program:

If PERSON.BIRTHSTATE = "CA" Then;
   Error ("California is too far West!");
End-If;

Here is what it looks like:

Code

Then, we need to change the state in our code from “XX” to “CA”.

Code

When our updates look like this:

updateCI(&emplid, True);

We get this in the log:

Output

When our updates look like this:

updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, True);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);

We get this in the log:

Selection_840

So, still no problem!

FieldChange Error

Okay, here is one more shot.  I removed my PeopleCode from the SavePreChange.  Next, I opened the FieldChange on the Birth State and put the PeopleCode in there.

Code

And here is what the log looks like:

Output

Still works right.

Conclusion

In conclusion, my goal was to demonstrate a bug in handling errors.  I think I failed because I wasn’t able to reproduce what I am seeing in production.

The problem I am seeing has to do with multiple updates.  The order matters, too.  We saw one instance where the last update erred, and everything worked fine.  Then on the next run, one of the middle updates erred, and the program stopped.  The weird part is that it finishes the PeopleCode program rather than stopping at the Save or where the error occurred.  Then, it abends the program at the end of that Step rather than finishing the whole App Engine.  So, what I was looking for was for it to not show that “Process Complete” message.

If anyone can figure out how to tweak this to reproduce the problem, please let me know.  I would love to demonstrate it so that maybe Oracle could try to fix the problem.  If nothing else though, maybe someone will find the code examples useful in creating their own programs.


Share

1 Comment

  1. Dan says:

    Looks like your test recreates the CI for each iteration. Have you tried creating it once and reusing it for each iteration? The response could be different. Also try multiple errors. I have a program where I’ve found the the message collection does not contain the current error after multiple errors have occurred.

    Dan

Leave a comment