AUTOMATIC1111/stable-diffusion-webui · error · RuntimeError

script {script_name} not found

Error message

script {script_name} not found

What it means

In ScriptRunner (modules/scripts.py), the helper that patches a specific script's argument looks up the target script by exact name equality over the registered script list. If no loaded script has that exact name, it raises RuntimeError('script {name} not found'). This API is typically used by extensions or API glue to inject values into another script's UI controls by elem_id.

Source

Thrown at modules/scripts.py:1012

                script.setup(p, *script_args)
            except Exception:
                errors.report(f"Error running setup: {script.filename}", exc_info=True)

    def set_named_arg(self, args, script_name, arg_elem_id, value, fuzzy=False):
        """Locate an arg of a specific script in script_args and set its value
        Args:
            args: all script args of process p, p.script_args
            script_name: the name target script name to
            arg_elem_id: the elem_id of the target arg
            value: the value to set
            fuzzy: if True, arg_elem_id can be a substring of the control.elem_id else exact match
        Returns:
            Updated script args
        when script_name in not found or arg_elem_id is not found in script controls, raise RuntimeError
        """
        script = next((x for x in self.scripts if x.name == script_name), None)
        if script is None:
            raise RuntimeError(f"script {script_name} not found")

        for i, control in enumerate(script.controls):
            if arg_elem_id in control.elem_id if fuzzy else arg_elem_id == control.elem_id:
                index = script.args_from + i

                if isinstance(args, tuple):
                    return args[:index] + (value,) + args[index + 1:]
                elif isinstance(args, list):
                    args[index] = value
                    return args
                else:
                    raise RuntimeError(f"args is not a list or tuple, but {type(args)}")
        raise RuntimeError(f"arg_elem_id {arg_elem_id} not found in script {script_name}")


scripts_txt2img: ScriptRunner = None
scripts_img2img: ScriptRunner = None
scripts_postproc: scripts_postprocessing.ScriptPostprocessingRunner = None

View on GitHub (pinned to 82a973c043)

Solutions

  1. Enable the target script under Settings > Scripts (or verify its file exists in scripts/ or the extension's scripts dir) and restart.
  2. Pass the exact internal script name (the `name` attribute / title shown in the scripts list), matching case and whitespace.
  3. List loaded scripts at runtime: `[s.name for s in script_runner.scripts]` to find the correct spelling.
  4. Ensure the call happens after scripts are initialized (inside a request handler, not at module import).

Example fix

# before
args = runner.set_named_arg(args, "xzy grid", "xyz_grid_x_values", "1,2,3")  # wrong name -> RuntimeError

# after
args = runner.set_named_arg(args, "xyz grid", "xyz_grid_x_values", "1,2,3")  # exact registered name
Defensive patterns

Strategy: type-guard

Validate before calling

def script_loaded(runner, script_name: str) -> bool:
    return any(s.name == script_name for s in runner.scripts)

if not script_loaded(runner, "xyz grid"):
    raise ValueError(f"script 'xyz grid' not loaded; loaded: {[s.name for s in runner.scripts]}")

Type guard

def find_script(runner, script_name: str):
    """Return the script with exactly matching name, or None."""
    return next((s for s in runner.scripts if s.name == script_name), None)

script = find_script(runner, "xyz grid")
if script is None:
    # handle gracefully: skip, log, or surface available names

Try / catch

try:
    args = runner.set_named_arg(args, script_name, elem_id, value)
except RuntimeError as e:
    if f"script {script_name} not found" in str(e):
        log.warning(f"{script_name} not loaded; available: {[s.name for s in runner.scripts]}")
        args = args  # leave unmodified, continue degraded
    else:
        raise

Prevention

When it happens

Trigger: Calling the set-arg helper with a script name that is not currently loaded: the script is disabled in Settings > Scripts, its .py file was removed from scripts/, the name has different casing/spacing, or the lookup runs before scripts are registered (e.g. during import instead of at request time).

Common situations: Extensions patching args of third-party scripts that the user disabled or uninstalled; renaming a script's title in its code while callers still pass the old name; ordering issues where the helper is invoked before the script runner populates self.scripts; API consumers passing UI labels instead of internal script names.

Related errors


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/0f6a3bc8bb5d181d. Report an issue: GitHub.