# Buggy code
def setOptions(self, options):
    """
    Creates a config object from the options object.
    """
    from bd2k.util.humanize import human2bytes  # This import is used to convert

    # from human readable quantites to integers
    def setOption(varName, parsingFn=None, checkFn=None):
        # If options object has the option "varName" specified
        # then set the "varName" attrib to this value in the config object
        x = getattr(options, varName, None)
        if x != None:
            if parsingFn != None:
                x = parsingFn(x)
            if checkFn != None:
                try:
                    checkFn(x)
                except AssertionError:
                    raise RuntimeError(
                        "The %s option has an invalid value: %s" % (varName, x)
                    )
            setattr(self, varName, x)

    h2b = lambda x: human2bytes(
        str(x)
    )  # Function to parse integer from string expressed in different formats

    def iC(minValue, maxValue=sys.maxint):
        # Returns function to check the a parameter is in a valid range
        def f(x):
            assert x >= minValue and x < maxValue

        return f

    # Core options
    setOption(
        "jobStore",
        parsingFn=lambda x: os.path.abspath(x)
        if options.jobStore.startswith(".")
        else x,
    )
    # TODO: LOG LEVEL STRING
    setOption("workDir")
    setOption("stats")
    setOption("clean")
    if self.stats:
        if self.clean != "never" and self.clean is not None:
            raise RuntimeError(
                "Contradicting options passed: Clean flag is set to %s "
                "despite the stats flag requiring "
                "the jobStore to be intact at the end of the run. "
                "Set clean to 'never'" % self.clean
            )
        self.clean = "never"
    elif self.clean is None:
        self.clean = "onSuccess"

    # Restarting the workflow options
    setOption("restart")

    # Batch system options
    setOption("batchSystem")
    setOption("scale", float)
    setOption("mesosMasterAddress")
    setOption("parasolCommand")
    setOption("parasolMaxBatches", int, iC(1))

    # Resource requirements
    setOption("defaultMemory", h2b, iC(1))
    setOption("defaultCores", h2b, iC(1))
    setOption("defaultDisk", h2b, iC(1))
    setOption("defaultCache", h2b, iC(0))
    setOption("maxCores", h2b, iC(1))
    setOption("maxMemory", h2b, iC(1))
    setOption("maxDisk", h2b, iC(1))

    # Retrying/rescuing jobs
    setOption("retryCount", int, iC(0))
    setOption("maxJobDuration", int, iC(1))
    setOption("rescueJobsFrequency", int, iC(1))

    # Misc
    setOption("maxLogFileSize", h2b, iC(1))

    def checkSse(sseKey):
        with open(sseKey) as f:
            assert len(f.readline().rstrip()) == 32

    setOption("sseKey", checkFn=checkSse)
    setOption("cseKey", checkFn=checkSse)

    # Debug options
    setOption("badWorker", float, iC(0, 1))
    setOption("badWorkerFailInterval", float, iC(0))


# Traceback (ConfigParser.NoSectionError)
DEBUG:toil.batchSystems.mesos.executor:Starting executor
I0924 22:47:08.587648 43191 exec.cpp:132] Version: 0.22.0
I0924 22:47:08.592193 43192 exec.cpp:206] Executor registered on slave 20150924-214557-83886090-5050-44087-S8
INFO:toil.batchSystems.mesos.executor:Registered with framework
DEBUG:toil.batchSystems.mesos.executor:Running task 0
DEBUG:toil.batchSystems.mesos.executor:Sending status update ...
DEBUG:toil.batchSystems.mesos.executor:Sent status update
DEBUG:toil.batchSystems.mesos.executor:Invoking command: '/usr/bin/python2.7 -E /usr/local/lib/python2.7/dist-packages/toil/worker.py azure:hgvm:tree2 683b1010_55c3_4978_a7e7_853f17ed1803'
DEBUG:toil.batchSystems.mesos.executor:Sent stats message
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/toil/worker.py", line 408, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/toil/worker.py", line 89, in main
jobStore = loadJobStore(jobStoreString)
File "/usr/local/lib/python2.7/dist-packages/toil/common.py", line 366, in loadJobStore
return AzureJobStore( account, namePrefix, config=config )
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/azureJobStore.py", line 78, in __init__
account_key = _fetchAzureAccountKey(accountName)
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/azureJobStore.py", line 63, in _fetchAzureAccountKey
return configParser.get('AzureStorageCredentials', accountName)
File "/usr/lib/python2.7/ConfigParser.py", line 330, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'AzureStorageCredentials'
DEBUG:toil.batchSystems.mesos.executor:Sending status update ...
DEBUG:toil.batchSystems.mesos.executor:Sent status update
I0924 22:47:09.738494 43200 exec.cpp:379] Executor asked to shutdown
CRITICAL:toil.batchSystems.mesos.executor:Shutting down executor...
CRITICAL:toil.batchSystems.mesos.executor:Executor shut down

# Fixed code
def setOptions(self, options):
    """
    Creates a config object from the options object.
    """
    from bd2k.util.humanize import human2bytes  # This import is used to convert

    # from human readable quantites to integers
    def setOption(varName, parsingFn=None, checkFn=None):
        # If options object has the option "varName" specified
        # then set the "varName" attrib to this value in the config object
        x = getattr(options, varName, None)
        if x != None:
            if parsingFn != None:
                x = parsingFn(x)
            if checkFn != None:
                try:
                    checkFn(x)
                except AssertionError:
                    raise RuntimeError(
                        "The %s option has an invalid value: %s" % (varName, x)
                    )
            setattr(self, varName, x)

    h2b = lambda x: human2bytes(
        str(x)
    )  # Function to parse integer from string expressed in different formats

    def iC(minValue, maxValue=sys.maxint):
        # Returns function to check the a parameter is in a valid range
        def f(x):
            assert x >= minValue and x < maxValue

        return f

    # Core options
    setOption(
        "jobStore",
        parsingFn=lambda x: os.path.abspath(x)
        if options.jobStore.startswith(".")
        else x,
    )
    # TODO: LOG LEVEL STRING
    setOption("workDir")
    setOption("stats")
    setOption("clean")
    if self.stats:
        if self.clean != "never" and self.clean is not None:
            raise RuntimeError(
                "Contradicting options passed: Clean flag is set to %s "
                "despite the stats flag requiring "
                "the jobStore to be intact at the end of the run. "
                "Set clean to 'never'" % self.clean
            )
        self.clean = "never"
    elif self.clean is None:
        self.clean = "onSuccess"

    # Restarting the workflow options
    setOption("restart")

    # Batch system options
    setOption("batchSystem")
    setOption("scale", float)
    setOption("mesosMasterAddress")
    setOption("parasolCommand")
    setOption("parasolMaxBatches", int, iC(1))

    setOption("environment", parseSetEnv)

    # Resource requirements
    setOption("defaultMemory", h2b, iC(1))
    setOption("defaultCores", h2b, iC(1))
    setOption("defaultDisk", h2b, iC(1))
    setOption("defaultCache", h2b, iC(0))
    setOption("maxCores", h2b, iC(1))
    setOption("maxMemory", h2b, iC(1))
    setOption("maxDisk", h2b, iC(1))

    # Retrying/rescuing jobs
    setOption("retryCount", int, iC(0))
    setOption("maxJobDuration", int, iC(1))
    setOption("rescueJobsFrequency", int, iC(1))

    # Misc
    setOption("maxLogFileSize", h2b, iC(1))

    def checkSse(sseKey):
        with open(sseKey) as f:
            assert len(f.readline().rstrip()) == 32

    setOption("sseKey", checkFn=checkSse)
    setOption("cseKey", checkFn=checkSse)

    # Debug options
    setOption("badWorker", float, iC(0, 1))
    setOption("badWorkerFailInterval", float, iC(0))