# Buggy code
async def train_async(
    domain: Union[Domain, Text],
    config: Text,
    training_files: Optional[Union[Text, List[Text]]],
    output_path: Text = DEFAULT_MODELS_PATH,
    force_training: bool = False,
    fixed_model_name: Optional[Text] = None,
    kwargs: Optional[Dict] = None,
) -> Optional[Text]:
    """Trains a Rasa model (Core and NLU).

    Args:
        domain: Path to the domain file.
        config: Path to the config for Core and NLU.
        training_files: Paths to the training data for Core and NLU.
        output_path: Output path.
        force_training: If `True` retrain model even if data has not changed.
        fixed_model_name: Name of model to be stored.
        kwargs: Additional training parameters.

    Returns:
        Path of the trained model archive.
    """
    skill_imports = SkillSelector.load(config, training_files)
    try:
        domain = Domain.load(domain, skill_imports)
        domain.check_missing_templates()
    except InvalidDomain as e:
        print_error(
            "Could not load domain due to error: {} \nTo specify a valid domain "
            "path, use the '--domain' argument.".format(e)
        )
        return None

    story_directory, nlu_data_directory = data.get_core_nlu_directories(
        training_files, skill_imports
    )

    with ExitStack() as stack:
        train_path = stack.enter_context(TempDirectoryPath(tempfile.mkdtemp()))
        nlu_data = stack.enter_context(TempDirectoryPath(nlu_data_directory))
        story = stack.enter_context(TempDirectoryPath(story_directory))

        return await _train_async_internal(
            domain,
            config,
            train_path,
            nlu_data,
            story,
            output_path,
            force_training,
            fixed_model_name,
            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_async(
    domain: Union[Domain, Text],
    config: Text,
    training_files: Optional[Union[Text, List[Text]]],
    output_path: Text = DEFAULT_MODELS_PATH,
    force_training: bool = False,
    fixed_model_name: Optional[Text] = None,
    kwargs: Optional[Dict] = None,
) -> Optional[Text]:
    """Trains a Rasa model (Core and NLU).

    Args:
        domain: Path to the domain file.
        config: Path to the config for Core and NLU.
        training_files: Paths to the training data for Core and NLU.
        output_path: Output path.
        force_training: If `True` retrain model even if data has not changed.
        fixed_model_name: Name of model to be stored.
        kwargs: Additional training parameters.

    Returns:
        Path of the trained model archive.
    """
    skill_imports = SkillSelector.load(config, training_files)
    try:
        domain = Domain.load(domain, skill_imports)
        domain.check_missing_templates()
    except InvalidDomain:
        domain = None

    story_directory, nlu_data_directory = data.get_core_nlu_directories(
        training_files, skill_imports
    )

    with ExitStack() as stack:
        train_path = stack.enter_context(TempDirectoryPath(tempfile.mkdtemp()))
        nlu_data = stack.enter_context(TempDirectoryPath(nlu_data_directory))
        story = stack.enter_context(TempDirectoryPath(story_directory))

        if domain is None:
            return handle_domain_if_not_exists(
                config, nlu_data_directory, output_path, fixed_model_name
            )

        return await _train_async_internal(
            domain,
            config,
            train_path,
            nlu_data,
            story,
            output_path,
            force_training,
            fixed_model_name,
            kwargs,
        )

    if domain is None:
        return handle_domain_if_not_exists(
            config, nlu_data_directory, output_path, fixed_model_name
        )