Purposely create compile error to fail the upload I would like to create a compile error so sketch does not upload in certain cases. 

I have written a library with a function that adds pins being used to an array. If the same pin is used twice I want to fail the compilation (preferably with an error that explains why). Is this possible?

void CheckPinNum(int newPinNum){
  for (int i=0; i &lt;= PinArrayLength; i++){
    if (newPinNum == PinArray[i])
      failCompilation("You entered same pin twice!");
  }
}
To answer the question asked in the title:

#if some_condition
# error Some error message
#endif


But note that this technique only works at compile time, which
probably makes it useless for you.