When I make an insert in a Spark.runtimeCollection, it should return (according documentation) true or false wether the insert succeed or fail.
If the insert leads to a duplicate key, there is a fatal error on the cloud code line and the script breaks.
I would expect to have false to be able to deal with the case.
You can catch this exception and return it using a try-catch block:
//insert operation here
var res = Spark.runtimeCollection("myCollection").insert(myDoc);
//print error message
res = false;
Hope this helps. If you have any more questions please don't hesitate to contact us.