When copy pasting files ensure end of file present as manual checksum

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the dumb-mistakes-and-gotchas category.

Last Updated: 2024-04-23

When working on Project S, I copied and pasted the env.js file into an encrypted channel and asked my team to download this file to their machines. It failed for them, causing us to spend 10 minutes debugging. It seemed the entire env variable, as exported from the file, was null...

The issue: I didn't copy the entire file. The last line, which did the actual exporting of content, was missing:

...
function getEnv() {
  const env = Constants.manifest.releaseChannel;
  if (env === null || env === undefined || env === "") return ENV[defaultEnv];
  if (env.indexOf("staging") !== -1) return ENV.staging;
  if (env.indexOf("production") !== -1) return ENV.production;
}

// LOOK HERE:

// Not present, but should have been!
// export default getEnv();

How on earth did this happen? Well I selected the text manually in my editor by moving the mouse to select before copying, rather than using a command for selecting the entire contents of the screen -- or using an OS finder to select the file itself.

Lesson

Ensure the end of a file is present when copy-pasting - think of this as a checksum.

Better yet, do not copy-paste file contents on screen to share whole files. Instead select the file itself (e.g. with finder).