For Case 1:
There is a cleanup method(you can see in function tabs of mapping) which will be executed after mapping.You can write logic here to write the file in case if the mapping program fails.
For Case 2:
In case of channel fails,You can configure alerts from alert inbox you can poll and write it as a file.