{"record":{"id":"8d60196d16604264","repo":"peass-ng/PEASS-ng","slug":"item-should-be-an-instance-of-linpeasmodule","errorCode":null,"errorMessage":"Item should be an instance of LinpeasModule","messagePattern":"Item should be an instance of LinpeasModule","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"linPEAS/builder/src/linpeasModule.py","lineNumber":279,"sourceCode":"\n    def index(self, item_id):\n        for index, module in enumerate(self):\n            if module.id == item_id:\n                return index\n        raise ValueError(f\"{item_id} is not in the list\")\n\n    def remove(self, item):\n        # If item is an id, find the corresponding object first.\n        if not isinstance(item, LinpeasModule):\n            index = self.index(item)\n            super().pop(index)\n        else:\n            super().remove(item)\n\n    def insert(self, index, item):\n        # Ensure that item is a LinpeasModule object before inserting.\n        if not isinstance(item, LinpeasModule):\n            raise ValueError(\"Item should be an instance of LinpeasModule\")\n        super().insert(index, item)\n    \n    def copy(self):\n        return LinpeasModuleList(super().copy())\n    ","sourceCodeStart":261,"sourceCodeEnd":284,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/linPEAS/builder/src/linpeasModule.py#L261-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"Loading modules from a config/JSON and inserting them directly instead of constructing LinpeasModule objects; appending placeholder entries during refactoring.","solutions":["Construct a LinpeasModule from the path before inserting: LinpeasModule(path)","Catch ValueError if the code must tolerate arbitrary input","Ensure helper code returns LinpeasModule instances, not dicts/strings"],"exampleFix":"# before\nmodules.insert(0, \"linpeas_parts/modules/system_regs.sh\")\n# after\nfrom src.linpeasModule import LinpeasModule\nmodules.insert(0, LinpeasModule(\"linpeas_parts/modules/system_regs.sh\"))","handlingStrategy":"type-guard","validationCode":"if not isinstance(item, LinpeasModule):\n    raise TypeError(f\"insert expects LinpeasModule, got {type(item).__name__}\")","typeGuard":"def is_linpeas_module(obj) -> bool:\n    from src.linpeasModule import LinpeasModule\n    return isinstance(obj, LinpeasModule)","tryCatchPattern":"try:\n    modules.insert(0, item)\nexcept ValueError as e:\n    print(f\"Bad insert: {e}; constructing LinpeasModule instead\")\n    modules.insert(0, LinpeasModule(item_path))","preventionTips":["Only insert values returned from LinpeasModule(...) constructors","Type-annotate helper functions with -> LinpeasModule","Add assert isinstance(item, LinpeasModule) at boundaries where items come from configs/JSON"],"tags":["python","type-safety","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}