# Buggy code
def _resolve_any_reference(self, builder, node, contnode):
    """Resolve reference generated by the "any" role."""
    refdoc = node["refdoc"]
    target = node["reftarget"]
    results = []
    # first, try resolving as :doc:
    doc_ref = self._resolve_doc_reference(builder, node, contnode)
    if doc_ref:
        results.append(("doc", doc_ref))
    # next, do the standard domain (makes this a priority)
    results.extend(
        self.domains["std"].resolve_any_xref(
            self, refdoc, builder, target, node, contnode
        )
    )
    for domain in self.domains.values():
        if domain.name == "std":
            continue  # we did this one already
        try:
            results.extend(
                domain.resolve_any_xref(self, refdoc, builder, target, node, contnode)
            )
        except NotImplementedError:
            # the domain doesn't yet support the new interface
            # we have to manually collect possible references (SLOW)
            for role in domain.roles:
                res = domain.resolve_xref(
                    self, refdoc, builder, role, target, node, contnode
                )
                if res:
                    results.append(("%s:%s" % (domain.name, role), res))
    # now, see how many matches we got...
    if not results:
        return None
    if len(results) > 1:
        nice_results = " or ".join(":%s:" % r[0] for r in results)
        self.warn_node(
            "more than one target found for 'any' cross-"
            "reference %r: could be %s" % (target, nice_results),
            node,
        )
    res_role, newnode = results[0]
    # Override "any" class with the actual role type to get the styling
    # approximately correct.
    res_domain = res_role.split(":")[0]
    if newnode and newnode[0].get("classes"):
        newnode[0]["classes"].append(res_domain)
        newnode[0]["classes"].append(res_role.replace(":", "-"))
    return newnode


# Traceback (AttributeError)
# Sphinx version: 1.3.3
# Python version: 2.7.8 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.8
# Last messages:
#
#   looking for now-outdated files...
#   none found
#   pickling environment...
#   done
#   checking consistency...
#   done
#   preparing documents...
#   done
#   writing output... [ 16%] api
# Loaded extensions:
#   sphinxcontrib.httpdomain (unknown version) from .virtualenvs/generic/local/lib/python2.7/site-packages/sphinxcontrib/httpdomain.pyc
#   alabaster (0.7.7) from .virtualenvs/generic/local/lib/python2.7/site-packages/alabaster/__init__.pyc
Traceback (most recent call last):
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/cmdline.py", line 240, in main
app.build(opts.force_all, filenames)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/application.py", line 266, in build
self.builder.build_update()
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 252, in build_update
'out of date' % len(to_build))
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 323, in build
self.write(docnames, list(updated_docnames), method)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 361, in write
self._write_serial(sorted(docnames), warnings)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 367, in _write_serial
doctree = self.env.get_and_resolve_doctree(docname, self)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/environment.py", line 1291, in get_and_resolve_doctree
self.resolve_references(doctree, docname, builder)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/environment.py", line 1549, in resolve_references
newnode = self._resolve_any_reference(builder, node, contnode)
File ".virtualenvs/generic/local/lib/python2.7/site-packages/sphinx/environment.py", line 1672, in _resolve_any_reference
if newnode and newnode[0].get('classes'):
AttributeError: 'Text' object has no attribute 'get'

# Fixed code
def _resolve_any_reference(self, builder, node, contnode):
    """Resolve reference generated by the "any" role."""
    refdoc = node["refdoc"]
    target = node["reftarget"]
    results = []
    # first, try resolving as :doc:
    doc_ref = self._resolve_doc_reference(builder, node, contnode)
    if doc_ref:
        results.append(("doc", doc_ref))
    # next, do the standard domain (makes this a priority)
    results.extend(
        self.domains["std"].resolve_any_xref(
            self, refdoc, builder, target, node, contnode
        )
    )
    for domain in self.domains.values():
        if domain.name == "std":
            continue  # we did this one already
        try:
            results.extend(
                domain.resolve_any_xref(self, refdoc, builder, target, node, contnode)
            )
        except NotImplementedError:
            # the domain doesn't yet support the new interface
            # we have to manually collect possible references (SLOW)
            for role in domain.roles:
                res = domain.resolve_xref(
                    self, refdoc, builder, role, target, node, contnode
                )
                if res and isinstance(res[0], nodes.Element):
                    results.append(("%s:%s" % (domain.name, role), res))
    # now, see how many matches we got...
    if not results:
        return None
    if len(results) > 1:
        nice_results = " or ".join(":%s:" % r[0] for r in results)
        self.warn_node(
            "more than one target found for 'any' cross-"
            "reference %r: could be %s" % (target, nice_results),
            node,
        )
    res_role, newnode = results[0]
    # Override "any" class with the actual role type to get the styling
    # approximately correct.
    res_domain = res_role.split(":")[0]
    if newnode and newnode[0].get("classes"):
        newnode[0]["classes"].append(res_domain)
        newnode[0]["classes"].append(res_role.replace(":", "-"))
    return newnode