Unable to get xml from modeler

Hello,

I am using modeler’s saveXml method to get xml string.
When I am not using an end event everyting works fine.
But if I use an end event or its derivatives(Message End Event, Signal End Event, etc…)
it fails with the error “ReferenceError: key is not defined”.
I am calling the method like this:

bpmnModeler.saveXML({ format: true }, function(err, xml) {
			    
	if(err){
			 
	     console.error(err);
    }

The error stack trace should give you a clear indication where the problem originates.

After a couple of wasted hours, I finally found the error.
If any error happens in the callback function then it catches like it happens in the saveXml method.For example:

bpmnModeler.saveXML({ format: true }, function(err, xml) {
       if(err){
			 
              console.error(err);
       }

       var x = bpmnJs/10;
});

This code throws “ReferenceError: bpmnJs is not defined”.And the stack trace points

BpmnModdle.toXML @ bpmn-moddle.js:77
Viewer.saveXML @ Viewer.js:197

A good pattern is:

foo(function(err, xml) {
  if (err) {
    console.log(err);
    // ensure we are not continuing to do stuff 
    return;
  }
});