Archi 4.7 (or superior) can't save a model or (if using coArchi) can't import, refresh or publish a model but instead gives "Error in model" - archimatetool/archi GitHub Wiki

Problem

When using Archi 4.7 or superior, you get a message dialog "Error in model" with a list of diagram connection sith the wrong source or target like this one:

image

You face this issue in one of those cases

  • When saving a model
  • When using coArchi and the "Import Remote Model to Workplace", "Refresh" or "Publish" feature

Why does this happen?

Archi 4.7 and later include better model validation controls and now won't allow you save a model in which the connection's ends in a view don't match the underlying model relationship's ends. This inconsistency should never appear in Archi, but in some (hopefully rare) cases, using coArchi and having people doing some weird things could lead to this.

So if this happened in the past on previous version of Archi, you might already own a model that can no more be saved on Archi 4.7 and superior. If this model is still shared through coArchi, you won't be able to import in because on import coArchi needs to load it in memory and save it.

In addition, while refreshing or publishing a model, you might raise this issue. Which will lead to the same error as the end of the refresh or publication process requires to save the model.

So how did my model get corrupted?

It's not possible to say exactly how your particular model became corrupted, however the following is a possible scenario:

  • Two users work on a model which contains (between others) a relationship R from A to B
  • User A creates a new view V using R, then publishes.
  • User B changes R so that it now goes from A to C, then publishes.
  • The result is a model in which a view V exists with a connection from A to B, this connection is related to relationship R which is between A and C !

How to solve it?

So we need to do the following steps to resolve this problem:

If this issue happened during a refresh or a publication, it might be easier to just restore the model from the commit which was the latest on the server, just before your action. If this is not possible, then:

  • Make a backup of Archi Model (just in case).
  • Close Archi and start it from command line adding the -noModelCheck option
  • Use a script to identify what is wrong (faulty relationships) with the model.
  • Document the model so we know how how to recreate the faulty relationships once they have been removed.
  • Run the script again, but this time use it to remove the faulty relationships.
  • Recreate the relationships in the model that were removed.
  • Commit and publish the fixed model back into your git server.
  • Open the model on a machine running a recent version of Archi and make sure everything is now working.

Step by Step

As always when trying to fix a problem, don't make it worse, so start by making sure you take a copy / backup of your Archi model.

Close Archi and start it again, but from command line adding the -noModelCheck option.

You now need to use a simple jArchi script that can identify what is wrong with the model and also remove the offending relationships from the model. Below is an example script provided by Jean-Baptiste Sarrodie that I used:

console.show();
console.clear();

$('view').find('relationship').each(function(connection) {
  var relation = connection.concept;
  var relationSource = relation.source;
  var relationTarget = relation.target;

  var connectionSource = connection.source.concept;
  var connectionTarget = connection.target.concept;
 
  if (connectionSource.id != relationSource.id || connectionTarget.id != relationTarget.id) {
    // Another approach could be to create another model relationship and to add it to the view instead of the unvalid one (more complicated to implement)
    console.log("In view \'", connection.view, "' : Visual connection", relation.type, " with id=", relation.id, " from ", connectionSource.type, " '", connectionSource.name, "' to ", connectionTarget.type, " '", connectionTarget.name, "' does not match underlying model relationship");
    // One way to solve the issue is to delete the visual connection:
    // connection.delete();
  }
});

console.log("End of validation");

Running this Jscript will provide you with list of views that have problems as well as the details of the relationship between the Source and Target in the console window. I recommend that you use this information and open each of views and save a PNG file for reference for when you need to recreate the relationship in the view. (File, Export, View As Image..)

Once you are confident you know what relationships in your model are causing problems, that you know how to recreate your view (should you have to) from your PNG snapshots, and you have a backup of you model you are ready for the next step.

Edit the script and this time change the //connection.delete(); to connection.delete();, to remove the comment and re-run the script. This time the offending relationships will be removed when the script runs.

Repairing the model

Now you should have a clean model, the next step is to add back in the relationships that you removed with the script. Once you have done this you can then save the model and commit the model back into your GIT repository and publish the changes.

Checking the fix

Finally, you can now open your model in a recent version of Archi. This time you shouldn't get any errors.