Adding Text to Numbers

The port now warns when NOTIFY_EMAIL is empty, exactly as the Python check does. Next comes the retry count. On the new server, BACKUP_RETRIES is "5", so the check should promise six attempts, counting the first try and five retries.

There’s a catch hiding in the quotes. Every environment variable arrives as text in both languages, and they disagree about what happens when that text meets a number. You’ll see one unconverted value give two kinds of answer and learn where to put the conversion so it can’t happen.

Read the Retry Count as Text

The Python check reads and converts the variable in one line. The next line logs the attempt count, and the last line logs the minutes the job may spend retrying, at ten minutes a retry:

Language: Python
import os

retries = int(os.environ.get("BACKUP_RETRIES", "3"))
print(f"Up to {retries + 1} attempts")
print(f"Up to {retries * 10} minutes of retries")

With BACKUP_RETRIES=5, the script prints the numbers the shop expects:

Language: Program Output
Up to 6 attempts
Up to 50 minutes of retries

That int() call is there because Python insists on it. Leave it out, and retries + 1 stops the script with TypeError: can only concatenate str (not "int") to str the first time the line runs.

In JavaScript, process.env.BACKUP_RETRIES gives you the same "5", a string. The first draft of backup-check.js ported the line that reads the variable as const retries = process.env.BACKUP_RETRIES;, and the int() didn’t make the trip.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.