# Buggy code
async def train_core_async(
    domain: Union[Domain, Text],
    config: Text,
    stories: Text,
    output: Text,
    train_path: Optional[Text] = None,
    fixed_model_name: Optional[Text] = None,
    kwargs: Optional[Dict] = None,
) -> Optional[Text]:
    """Trains a Core model.

    Args:
        domain: Path to the domain file.
        config: Path to the config file for Core.
        stories: Path to the Core training data.
        output: Output path.
        train_path: If `None` the model will be trained in a temporary
            directory, otherwise in the provided directory.
        fixed_model_name: Name of model to be stored.
        uncompress: If `True` the model will not be compressed.
        kwargs: Additional training parameters.

    Returns:
        If `train_path` is given it returns the path to the model archive,
        otherwise the path to the directory with the trained model files.

    """

    skill_imports = SkillSelector.load(config, stories)

    if isinstance(domain, str):
        try:
            domain = Domain.load(domain, skill_imports)
            domain.check_missing_templates()
        except InvalidDomain as e:
            print_error(
                "Could not load domain due to: '{}'. To specify a valid domain path "
                "use the '--domain' argument.".format(e)
            )
            return None

    train_context = TempDirectoryPath(data.get_core_directory(stories, skill_imports))

    with train_context as story_directory:
        if not os.listdir(story_directory):
            print_error(
                "No stories given. Please provide stories in order to "
                "train a Rasa Core model using the '--stories' argument."
            )
            return

        return await _train_core_with_validated_data(
            domain=domain,
            config=config,
            story_directory=story_directory,
            output=output,
            train_path=train_path,
            fixed_model_name=fixed_model_name,
            kwargs=kwargs,
        )


# Traceback (AttributeError)
docker run -v $(pwd)/data:/app/data rasa/rasa:latest-full train core --config /app/data/config.yml --stories /app/data/stories --out /app/data/models --augmentation 0 --quiet
2019-06-15 00:52:47 ERROR    rasa.core.training.dsl  - Error in line 2: 'NoneType' object has no attribute 'intents'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 301, in process_lines
await self.add_user_messages(user_messages, line_num)
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 383, in add_user_messages
*[self._parse_message(m, line_num) for m in messages]
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 367, in _parse_message
if intent_name not in self.domain.intents:
AttributeError: 'NoneType' object has no attribute 'intents'
2019-06-15 00:52:47 ERROR    rasa.core.training.dsl  - Invalid story file format. Failed to parse '/tmp/tmpz84lkggv/c24e99a4b7ff480f80047ec55ce5b484_claimzen.md'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 301, in process_lines
await self.add_user_messages(user_messages, line_num)
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 383, in add_user_messages
*[self._parse_message(m, line_num) for m in messages]
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 367, in _parse_message
if intent_name not in self.domain.intents:
AttributeError: 'NoneType' object has no attribute 'intents'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 214, in read_from_file
return await reader.process_lines(lines)
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 313, in process_lines
raise ValueError(msg)
ValueError: Error in line 2: 'NoneType' object has no attribute 'intents'
Training Core model...
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 301, in process_lines
await self.add_user_messages(user_messages, line_num)
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 383, in add_user_messages
*[self._parse_message(m, line_num) for m in messages]
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 367, in _parse_message
if intent_name not in self.domain.intents:
AttributeError: 'NoneType' object has no attribute 'intents'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/rasa", line 10, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/rasa/__main__.py", line 70, in main
cmdline_arguments.func(cmdline_arguments)
File "/usr/local/lib/python3.6/site-packages/rasa/cli/train.py", line 121, in train_core
kwargs=extract_additional_arguments(args),
File "/usr/local/lib/python3.6/site-packages/rasa/train.py", line 215, in train_core
kwargs=kwargs,
File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
File "/usr/local/lib/python3.6/site-packages/rasa/train.py", line 277, in train_core_async
kwargs=kwargs,
File "/usr/local/lib/python3.6/site-packages/rasa/train.py", line 303, in _train_core_with_validated_data
kwargs=kwargs,
File "/usr/local/lib/python3.6/site-packages/rasa/core/train.py", line 57, in train
stories_file, exclusion_percentage=exclusion_percentage, **data_load_args
File "/usr/local/lib/python3.6/site-packages/rasa/core/agent.py", line 616, in load_data
exclusion_percentage=exclusion_percentage,
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/__init__.py", line 50, in load_data
resource_name, domain, exclusion_percentage=exclusion_percentage
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/__init__.py", line 29, in extract_story_graph
exclusion_percentage=exclusion_percentage,
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 186, in read_from_folder
f, domain, interpreter, template_variables, use_e2e
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 214, in read_from_file
return await reader.process_lines(lines)
File "/usr/local/lib/python3.6/site-packages/rasa/core/training/dsl.py", line 313, in process_lines
raise ValueError(msg)

# Fixed code
async def train_core_async(
    domain: Union[Domain, Text],
    config: Text,
    stories: Text,
    output: Text,
    train_path: Optional[Text] = None,
    fixed_model_name: Optional[Text] = None,
    kwargs: Optional[Dict] = None,
) -> Optional[Text]:
    """Trains a Core model.

    Args:
        domain: Path to the domain file.
        config: Path to the config file for Core.
        stories: Path to the Core training data.
        output: Output path.
        train_path: If `None` the model will be trained in a temporary
            directory, otherwise in the provided directory.
        fixed_model_name: Name of model to be stored.
        uncompress: If `True` the model will not be compressed.
        kwargs: Additional training parameters.

    Returns:
        If `train_path` is given it returns the path to the model archive,
        otherwise the path to the directory with the trained model files.

    """

    skill_imports = SkillSelector.load(config, stories)

    try:
        domain = Domain.load(domain, skill_imports)
        domain.check_missing_templates()
    except InvalidDomain:
        print_error(
            "Core training was skipped because no valid domain file was found. "
            "Please specify a valid domain using '--domain' argument or check if the provided domain file exists."
        )
        return None

    train_context = TempDirectoryPath(data.get_core_directory(stories, skill_imports))

    with train_context as story_directory:
        if not os.listdir(story_directory):
            print_error(
                "No stories given. Please provide stories in order to "
                "train a Rasa Core model using the '--stories' argument."
            )
            return

        return await _train_core_with_validated_data(
            domain=domain,
            config=config,
            story_directory=story_directory,
            output=output,
            train_path=train_path,
            fixed_model_name=fixed_model_name,
            kwargs=kwargs,
        )