public default <S> S getScopeValue(final Pop pop, final Object key, final Traverser.Admin<?> traverser) throws KeyNotFoundException {
        final Object object = traverser.get();
        if (object instanceof Map && ((Map) object).containsKey(key))
            return (S) ((Map) object).get(key);

        if (key instanceof String) {
            final String k = (String) key;
            if (traverser.getSideEffects().exists(k))
                return traverser.getSideEffects().get(k);

            final Path path = traverser.path();
            if (path.hasLabel(k))
                return null == pop ? path.get(k) : path.get(pop, k);
        }

        throw new KeyNotFoundException(key, this);
    }
Finds the object with the specified key for the current traverser and throws an exception if the key cannot
be found.

@throws KeyNotFoundException if the key does not exist
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java