# Buggy code
def __getattr__(self, attr):
    """Handle unknown attributes.

    Often the actual object returned is not the object that is expected. In
    those cases attempting to retrieve a specific named attribute would
    normally raise, e.g.:

    fd = aff4.FACTORY.Open(urn)
    fd.Get(fd.Schema.DOESNTEXIST, default_value)

    In this case we return None to ensure that the default is chosen.

    However, if the caller specifies a specific aff4_type, they expect the
    attributes of that object. If they are referencing a non-existent
    attribute this is an error and we should raise, e.g.:

    fd = aff4.FACTORY.Open(urn, aff4_type="something")
    fd.Get(fd.Schema.DOESNTEXIST, default_value)

    Args:
      attr: Some ignored attribute.
    Raises:
      BadGetAttributeError: if the object was opened with a specific type
    """
    if self.aff4_type:
        raise BadGetAttributeError(
            "Attribute %s does not exist on object opened with aff4_type %s"
            % (utils.SmartStr(attr), self.aff4_type)
        )

    return None


# Traceback (ArtifactNotRegisteredError)
Traceback (most recent call last): File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow_runner.py", line 644, in RunStateMethod responses=responses) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow.py", line 346, in Decorated res = f(*args[:f.func_code.co_argcount]) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flows/general/discovery.py", line 153, in Platform next_state="ProcessKnowledgeBase") File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow.py", line 784, in CallFlow **kwargs) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow_runner.py", line 940, in CallFlow **kwargs) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow.py", line 927, in StartFlow flow_obj.Start() File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/flow.py", line 346, in Decorated res = f(*args[:f.func_code.co_argcount]) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/artifact.py", line 143, in Start first_flows = self.GetFirstFlowsForCollection() File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/artifact.py", line 407, in GetFirstFlowsForCollection artifact_registry.REGISTRY.GetArtifact(artifact_name) File "/usr/share/grr-server/local/lib/python2.7/site-packages/grr/lib/artifact_registry.py", line 304, in GetArtifact "directory." % name) ArtifactNotRegisteredError: Artifact WMIProfileUsersHomeDir missing from registry. You may need to sync the artifact repo by running make in the artifact directory.

# Fixed code
def __getattr__(self, attr):
    """Handle unknown attributes.

    Often the actual object returned is not the object that is expected. In
    those cases attempting to retrieve a specific named attribute would
    normally raise, e.g.:

    fd = aff4.FACTORY.Open(urn)
    fd.Get(fd.Schema.DOESNTEXIST, default_value)

    In this case we return None to ensure that the default is chosen.

    However, if the caller specifies a specific aff4_type, they expect the
    attributes of that object. If they are referencing a non-existent
    attribute this is an error and we should raise, e.g.:

    fd = aff4.FACTORY.Open(urn, aff4_type=module.SomeClass)
    fd.Get(fd.Schema.DOESNTEXIST, default_value)

    Args:
      attr: Some ignored attribute.
    Raises:
      BadGetAttributeError: if the object was opened with a specific type
    """
    if self.aff4_type:
        raise BadGetAttributeError(
            "Attribute %s does not exist on object opened with aff4_type %s"
            % (utils.SmartStr(attr), self.aff4_type)
        )

    return None