Prevent null string from causing undefined behavior and return default error message.