# Buggy code
def perform_svtextin_node_object(node, node_ref):
    """
    as it's a beta service, old IO json may not be compatible - in this interest
    of neat code we assume it finds everything.
    """
    texts = bpy.data.texts
    params = node_ref.get("params")
    current_text = params["current_text"]

    # it's not clear from the exporter code why textmode parameter isn't stored
    # in params.. for now this lets us look in both places. ugly but whatever.
    textmode = params.get("textmode")
    if not textmode:
        textmode = node_ref.get("textmode")
    node.textmode = textmode

    if not current_text:
        info("`%s' doesn't store a current_text in params", node.name)

    elif not current_text in texts:
        new_text = texts.new(current_text)
        text_line_entry = node_ref["text_lines"]

        if node.textmode == "JSON":
            if isinstance(text_line_entry, str):
                debug("loading old text json content / backward compatibility mode")
                pass

            elif isinstance(text_line_entry, dict):
                text_line_entry = json.dumps(text_line_entry["stored_as_json"])

        new_text.from_string(text_line_entry)

    else:
        # reaches here if  (current_text) and (current_text in texts)
        # can probably skip this..
        # texts[current_text].from_string(node_ref['text_lines'])
        debug(
            "%s seems to reuse a text block loaded by another node - skipping",
            node.name,
        )


# Traceback (KeyError)
======================================================================
ERROR: test_import_examples (tree_import_tests.ExamplesImportTest) (file='5.Sverchok_Spread.json')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/portnov/.config/blender/2.79/scripts/addons/sverchok-master/tests/tree_import_tests.py", line 66, in test_import_examples
import_tree(new_tree, path)
File "/home/portnov/.config/blender/2.79/scripts/addons/sverchok-master/utils/sv_IO_panel_tools.py", line 729, in import_tree
generate_layout(fullpath, nodes_json)
File "/home/portnov/.config/blender/2.79/scripts/addons/sverchok-master/utils/sv_IO_panel_tools.py", line 711, in generate_layout
place_frames(ng, nodes_json, name_remap)
File "/home/portnov/.config/blender/2.79/scripts/addons/sverchok-master/utils/sv_IO_panel_tools.py", line 638, in place_frames
ng.nodes[finalize(node_name)].parent = ng.nodes[finalize(parent)]
KeyError: 'bpy_prop_collection[key]: key "Text in+.001" not found'

# Fixed code
def perform_svtextin_node_object(node, node_ref):
    """
    as it's a beta service, old IO json may not be compatible - in this interest
    of neat code we assume it finds everything.
    """
    texts = bpy.data.texts
    params = node_ref.get("params")

    # original textin used 'current_text', textin+ uses 'text'
    current_text = params.get("current_text", params.get("text"))

    # it's not clear from the exporter code why textmode parameter isn't stored
    # in params.. for now this lets us look in both places. ugly but whatever.
    textmode = params.get("textmode")
    if not textmode:
        textmode = node_ref.get("textmode")
    node.textmode = textmode

    if not current_text:
        info("`%s' doesn't store a current_text in params", node.name)

    elif not current_text in texts:
        new_text = texts.new(current_text)
        text_line_entry = node_ref["text_lines"]

        if node.textmode == "JSON":
            if isinstance(text_line_entry, str):
                debug("loading old text json content / backward compatibility mode")

            elif isinstance(text_line_entry, dict):
                text_line_entry = json.dumps(text_line_entry["stored_as_json"])

        new_text.from_string(text_line_entry)

    else:
        # reaches here if  (current_text) and (current_text in texts)
        # can probably skip this..
        # texts[current_text].from_string(node_ref['text_lines'])
        debug(
            "%s seems to reuse a text block loaded by another node - skipping",
            node.name,
        )