Skip to content

AutoUnload instances won't be unloaded if the plugin failed to load successfully #119

Description

@KirillMysnik

Code to reproduce

from core import echo_console
from events import Event


@Event('player_jump')
def on_player_jump(game_event):
    echo_console("Player has jumped")


raise Exception("Too bad. But no.")

Result

] sp load autounloadtest
[SP] Loading plugin 'autounloadtest'... 

[SP] Caught an Exception: 
Traceback (most recent call last): 
  File '..\addons\source-python\packages\source-python\plugins\manager.py', line 71, in __missing__ 
    instance = self.instance(plugin_name, self.base_import) 
  File '..\addons\source-python\packages\source-python\plugins\instance.py', line 82, in __init__ 
    self._plugin = import_module(import_name) 
  File '..\addons\source-python\plugins\autounloadtest\autounloadtest.py', line 10, in <module> 
    raise Exception('Too bad. But no.') 

Exception: Too bad. But no. 


[SP] Plugin 'autounloadtest' was unable to be loaded. 

But the Event is still registered, e.g. if you jump, it will print Player has jumped to the console.

Additionaly, I looked through load_and_unload branch, and did not find any mechanism to prevent this either.

Possible solution

As we don't have access to the globals of the plugin (because it was unable to load) and can't really iter over them to hunt AutoUnload instances, it maybe worth just checking the difference between a set of existing AutoUnload instances before plugin was trying to load, and a set of existing AutoUnload instances after the plugin was loaded or failed to load.
This way we will recognize new AutoUnload instances even if they were created by the failing plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions