Same problem here. Got the "Could not save as 'filename' because of a program error." ( 356mb file with 16 layers ) and went through everything layer by layer.
Eventually narrowed it down to one layer mask. Copied the mask to a new layer, deleted the offending layer mask, hit save, done.
No idea what was wrong with that particular mask but 3hours worth of work eventually got saved.