code: func (r *EtcdRegistry) dirToUnit(dir *etcd.Node, unitHashLookupFunc func(unit.Hash) *unit.UnitFile) (*job.Unit, error) {
  	objKey := path.Join(dir.Key, "object")
  	var objNode *etcd.Node
  	for _, node := range dir.Nodes {
  		node := node
  		if node.Key == objKey {
  			objNode = node
  		}
  	}
  	if objNode == nil {
  		return nil, nil
  	}
  	u, err := r.getUnitFromObjectNode(objNode, unitHashLookupFunc)
  	if err != nil {
  		return nil, err
  	}
  	if u == nil {
  		return nil, fmt.Errorf("unable to parse Unit in Registry at key %s", objKey)
  	}
  	if tgtstate := dirToTargetState(dir); tgtstate != "" {
  		ts, err := job.ParseJobState(tgtstate)
  		if err != nil {
  			return nil, fmt.Errorf("failed to parse Unit(%s) target-state: %v", u.Name, err)
  		}
  		u.TargetState = ts
  	}
  
  	return u, nil
  }
docs: // dirToUnit takes a Node containing a Job's constituent objects (in child
  // nodes) and returns a *job.Unit, or any error encountered