# Buggy code
def _unsafe_process(self, fname, in_str=None, config=None):
    if not config:
        raise ValueError(
            "For the dbt templater, the `process()` method requires a config object."
        )
    if not fname:
        raise ValueError(
            "For the dbt templater, the `process()` method requires a file name"
        )
    elif fname == "stdin":
        raise ValueError(
            "The dbt templater does not support stdin input, provide a path instead"
        )
    self.sqlfluff_config = config

    selected = self.dbt_selector_method.search(
        included_nodes=self.dbt_manifest.nodes,
        # Selector needs to be a relative path
        selector=os.path.relpath(fname, start=os.getcwd()),
    )
    results = [self.dbt_manifest.expect(uid) for uid in selected]

    if not results:
        raise RuntimeError("File %s was not found in dbt project" % fname)

    node = self.dbt_compiler.compile_node(
        node=results[0],
        manifest=self.dbt_manifest,
    )

    if not node.compiled_sql:
        raise SQLTemplaterError(
            "dbt templater compilation failed silently, check your configuration "
            "by running `dbt compile` directly."
        )

    raw_sliced, sliced_file = self.slice_file(node.raw_sql, node.compiled_sql)
    return (
        TemplatedFile(
            source_str=node.raw_sql,
            templated_str=node.compiled_sql,
            fname=fname,
            sliced_file=sliced_file,
            raw_sliced=raw_sliced,
        ),
        # No violations returned in this way.
        [],
    )


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/bin/sqlfluff", line 11, in <module>
load_entry_point('sqlfluff', 'console_scripts', 'sqlfluff')()
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/niallwoodward/dev/pull_requests/dbt_sqlfluff_venv/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/cli/commands.py", line 323, in lint
ignore_files=not disregard_sqlfluffignores,
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 1161, in lint_paths
ignore_files=ignore_files,
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 1139, in lint_path
target_file.read(), fname=fname, fix=fix, config=config
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 939, in lint_string
parsed = self.parse_string(in_str=in_str, fname=fname, config=config)
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/linter.py", line 723, in parse_string
tokens, lex_vs = lexer.lex(templated_file)
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/parser/lexer.py", line 343, in lex
return self.enrich_segments(segment_buff, raw), violations
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/parser/lexer.py", line 373, in enrich_segments
templated_slice
File "/Users/niallwoodward/dev/pull_requests/sqlfluff/src/sqlfluff/core/templaters/base.py", line 283, in templated_slice_to_source_slice
elif start_slices[0][0] == "literal":
IndexError: list index out of range

# Fixed code
def _unsafe_process(self, fname, in_str=None, config=None):
    if not config:
        raise ValueError(
            "For the dbt templater, the `process()` method requires a config object."
        )
    if not fname:
        raise ValueError(
            "For the dbt templater, the `process()` method requires a file name"
        )
    elif fname == "stdin":
        raise ValueError(
            "The dbt templater does not support stdin input, provide a path instead"
        )
    self.sqlfluff_config = config

    selected = self.dbt_selector_method.search(
        included_nodes=self.dbt_manifest.nodes,
        # Selector needs to be a relative path
        selector=os.path.relpath(fname, start=os.getcwd()),
    )
    results = [self.dbt_manifest.expect(uid) for uid in selected]

    if not results:
        raise RuntimeError("File %s was not found in dbt project" % fname)

    node = self.dbt_compiler.compile_node(
        node=results[0],
        manifest=self.dbt_manifest,
    )

    if hasattr(node, "injected_sql"):
        # If injected SQL is present, it contains a better picture
        # of what will actually hit the database (e.g. with tests).
        # However it's not always present.
        compiled_sql = node.injected_sql
    else:
        compiled_sql = node.compiled_sql

    if not compiled_sql:
        raise SQLTemplaterError(
            "dbt templater compilation failed silently, check your configuration "
            "by running `dbt compile` directly."
        )

    raw_sliced, sliced_file, templated_sql = self.slice_file(
        node.raw_sql, compiled_sql, config=config
    )
    return (
        TemplatedFile(
            source_str=node.raw_sql,
            templated_str=templated_sql,
            fname=fname,
            sliced_file=sliced_file,
            raw_sliced=raw_sliced,
        ),
        # No violations returned in this way.
        [],
    )