Skip to content

Traceback on imagefunc.py, sporadic issue #144

@hwprinz

Description

@hwprinz

Hi,

sporadically you might get (as an example)

[2026-02-28 12:22:21.564] Traceback (most recent call last):
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\execution.py", line 518, in execute
    output_data, output_ui, has_subgraph, has_pending_tasks = await get_output_data(prompt_id, unique_id, obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\execution.py", line 329, in get_output_data
    return_values = await _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb, v3_data=v3_data)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\execution.py", line 303, in _async_map_node_over_list
    await process_inputs(input_dict, i)
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\execution.py", line 291, in process_inputs
    result = f(**inputs)
             ^^^^^^^^^^^
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\custom_nodes\ComfyUI-LayerStyle-Advance\py\save_image_plus.py", line 74, in save_image_plus
    _u = add_invisibal_watermark(u, qr_image)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\ComfyUI\ComfyUI_windows_portable1\ComfyUI\custom_nodes\ComfyUI-LayerStyle-Advance\py\imagefunc.py", line 1298, in add_invisibal_watermark
    shutil.rmtree(temp_dir)
    ^^^^^^
NameError: name 'shutil' is not defined. Did you forget to import 'shutil'

after digging into it (thanks to Claude as well) it turned out:
Look at line 1298/1306

if os.path.isdir(temp_dir):
    shutil.rmtree(temp_dir)

Claude says:
shutil is only called if the temp directory already exists. Since the temp dir name is randomly generated each run, it almost never exists — so that line is almost never reached, and the import is never missed.
The crash only happens on that rare random name collision. Which explains exactly what you observed — works fine 90%+ of the time, fails occasionally for no obvious reason.
So the node isn't broken in normal use, it just has a latent bug hiding behind a very unlikely condition. The fix is still worth doing since it will make those rare failures disappear completely.

The fix is more than simple:
add the missing 'import shutil' at the beginning of imagefunc.py

like:

Image

Thanks /Hans

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions