Hello Mettigel,
cameras=[c.key for c in chunk.cameras if c.type == Metashape.Camera.Type.Regular] - provides the list of int, as required for cameras argument, unique id of each camera in the chunk, excluding animation cameras, if any.
As for the original issue, I think, you can use try/except concept to avoid the script being terminated by "RuntimeError: Can't open file" message related to missing mask images. Note that in case of corrupted mask file the exception will be different: "RuntimeError: Can't load image".
Another possible solution is to get the list of mask files in the source folder, then form the list of cameras to be used in generateMasks.