S3 - Check for code attr before using in error message

Fixes #7120.