Updated error handling to include trace