Failure Handling : How to determine the Failure Definition Id to target

Failure Handling : How to determine the Failure Definition Id to target

harilalmn
Advocate Advocate
352 Views
1 Reply
Message 1 of 2

Failure Handling : How to determine the Failure Definition Id to target

harilalmn
Advocate
Advocate

Dear all,

When we have a process failure during a transaction, how can we determine which built-in failure definition id to check for? For example, I have the following errors / warnings as shown in the image below;

 

 

Error.png

 

I am trying to handle these using the class below;

 

 

 

public class WallWarningSwallower : IFailuresPreprocessor
{
    public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
    {
        IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
        if (fmas.Count == 0)
        {
            return FailureProcessingResult.Continue;
        }

        bool isResolved = false;

        foreach (FailureMessageAccessor fma in fmas)
        {
            if (
                fma.GetFailureDefinitionId() == BuiltInFailures.JoinElementsFailures.CannotJoinElements ||
                fma.GetFailureDefinitionId() == BuiltInFailures.JoinElementsFailures.CannotKeepJoined ||
                fma.GetFailureDefinitionId() == BuiltInFailures.CutFailures.CannotCutInstanceOut ||
                fma.GetFailureDefinitionId() == BuiltInFailures.OverlapFailures.DuplicateInstances
                )
            {
                failuresAccessor.DeleteWarning(fma);
                failuresAccessor.ResolveFailure(fma);
            }
        }
        return FailureProcessingResult.Continue;
    }
}

 

 

 

But still the warnings and errors are shown. So, how to handle these errors...?

0 Likes
353 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

Since you are handling errors that need to be resolved in order to continue, and not just swallowing warnings that can be ignored, the first thing to do is to rename your implementation class appropriately. Naming it WallWarningSwallower is sure to confuse the human reader of your code. At least it confuses me. Your wording and approach to the problem confuses me as well. Have you looked at other failure processing approaches described in The Building Coder topic group and in previous threads here in the forum? There are many, and they possibly describe a more appropriate approach:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes