cil_write_ast: improve error handling am: 6369bbbd96
am: b9e0d3d19c

Change-Id: I12a516e2acabc2a7d21bc523f906f6464a4b1082