Added error handling for thumbnail generation.