peass-ng/PEASS-ng · error · ValueError

Item should be an instance of LinpeasModule

Error message

Item should be an instance of LinpeasModule

What it means

LinpeasModuleList.insert() is a typed-collection guard: it only accepts LinpeasModule instances and raises ValueError for anything else, preventing raw dicts, strings, or paths from corrupting the module list that downstream build steps iterate over.

Source

Thrown at linPEAS/builder/src/linpeasModule.py:279

    def index(self, item_id):
        for index, module in enumerate(self):
            if module.id == item_id:
                return index
        raise ValueError(f"{item_id} is not in the list")

    def remove(self, item):
        # If item is an id, find the corresponding object first.
        if not isinstance(item, LinpeasModule):
            index = self.index(item)
            super().pop(index)
        else:
            super().remove(item)

    def insert(self, index, item):
        # Ensure that item is a LinpeasModule object before inserting.
        if not isinstance(item, LinpeasModule):
            raise ValueError("Item should be an instance of LinpeasModule")
        super().insert(index, item)
    
    def copy(self):
        return LinpeasModuleList(super().copy())
    

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Construct a LinpeasModule from the path before inserting: LinpeasModule(path)
  2. Catch ValueError if the code must tolerate arbitrary input
  3. Ensure helper code returns LinpeasModule instances, not dicts/strings

Example fix

# before
modules.insert(0, "linpeas_parts/modules/system_regs.sh")
# after
from src.linpeasModule import LinpeasModule
modules.insert(0, LinpeasModule("linpeas_parts/modules/system_regs.sh"))
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(item, LinpeasModule):
    raise TypeError(f"insert expects LinpeasModule, got {type(item).__name__}")

Type guard

def is_linpeas_module(obj) -> bool:
    from src.linpeasModule import LinpeasModule
    return isinstance(obj, LinpeasModule)

Try / catch

try:
    modules.insert(0, item)
except ValueError as e:
    print(f"Bad insert: {e}; constructing LinpeasModule instead")
    modules.insert(0, LinpeasModule(item_path))

Prevention

When it happens

Trigger: Calling LinpeasModuleList.insert(idx, item) where item is not constructed via LinpeasModule(...) — e.g. a dict parsed from JSON, a file path string, or a None placeholder.

Common situations: Loading modules from a config/JSON and inserting them directly instead of constructing LinpeasModule objects; appending placeholder entries during refactoring.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/8d60196d16604264. Report an issue: GitHub.