Provide information/support to user when save fails

Issue #317 new
Matthias Schoettle created an issue

Unfortunately it happens frequently that saving a model fails with a DanglingHREFException. For some reason, this is caught in certain cases, but not in all (saving to a new vs. existing file). We need to make sure to catch this in all cases and provide assistance to the user. The current error message is not helpful.

I suggest the following when this is detected:

  • An error message is presented to the user that provides information about the element that is referenced, but also, which elements still reference it. The cross referencer provided by EMF could be helpful for this (EcoreUtil.UsageCrossReferencer.find(...)).
  • The user then has the choice to fix this problem by undoing previous actions or removing the reference.

In the case that it is not the users fault that this happened (bugs in the executed commands) we should provide help in order for the user to be able to retain the current state of the model and not lose it.

Comments (2)

  1. Matthias Schoettle reporter

    The reason the exception is caught once is that the AspectFileBrowser calls aspect.eResource().save(...) if the aspect was previously saved, otherwise, it calls ResourceManager.saveModel(...). The latter catches the exception and just returns a boolean.

    I think the problematic references should be detected before saving (on save request). The problematic references could be found through (unfortunately, EcoreUtil.getRootContainer(...) does not return null if it's not contained:

    TreeIterator<EObject> iterator = aspect.eAllContents();
    while (iterator.hasNext()) {
        EObject eObject = iterator.next();
    
        for (EObject crossReference : eObject.eCrossReferences()) {
            if ((aspect.eResource() != null && crossReference.eResource() == null) 
                    || crossReference.eContainer() == null
                    || EMFModelUtil.getRootContainerOfType(crossReference, RamPackage.Literals.ASPECT) == null) {
                // dangling reference found
            }
        }
    }
    

    Or through EMF's validation mechanism. However, it will report all kinds of problems and only works if the model was previously saved.

    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(aspect, Diagnostician.INSTANCE.createDefaultContext());
    
  2. Log in to comment