tl;dr: When working on a WTF bug, I always remember my friend and programming mentor Matthew Hayes’ advice: “Be scientific, and eliminate the possible causes one by one.”

Indulge me as I document my boneheadedness today.

Had to complete a menial dev task: “Download a bunch of files off a server”. No problem. The files were named in a nice convenient pattern: http://server/dir/xyz.rpt, where xyz is 001 through 843.

No problem at all. In a jiffy, created a file in Sublime with 843 lines - one for each file. Then on the command line:

wget -i myfile.txt

… at which point the command line gave me a 400 Not Found error.

Hmm. Copy the first line. Run it on the command line:

wget http://server/dir/001.rpt

That download worked perfectly. What’s wrong with the first one? Maybe it’s a special character I’m not encoding. 2nd attempt: put quotes around the URLs in my file, as in: wget “http://server/dir/001.rpt” and run again.

400 Not Found.

What could be going on? The wget command looks exactly the same in both places.

Stop. Think. Which of your assumptions is wrong?

Let’s look at those error messages very closely. Maybe the commands aren’t exactly the same…

Ah-a! What’s that extra %0D in the URL when running the file? Turns out it’s the CR (carriage return) character. My line endings in Sublime had somehow switched from Unix to Mac, which meant Unix was reading my line endings as a part of the URL.

Change it back.

Try again:

wget -i myfile.txt

Presto! It works!

Now I remember not to panic or waste time when I encounter silly bugs. I just start by examining my own assumptions first and then eliminating the problems in there.