You should use Spark's Logging class to log an error instead of System.err