Skip to content

Add hook.ProtectedRun and hook.ProtectedCall functions#2175

Open
Srlion wants to merge 1 commit intoFacepunch:masterfrom
Srlion:master
Open

Add hook.ProtectedRun and hook.ProtectedCall functions#2175
Srlion wants to merge 1 commit intoFacepunch:masterfrom
Srlion:master

Conversation

@Srlion
Copy link
Copy Markdown
Contributor

@Srlion Srlion commented Dec 18, 2024

hook.ProtectedCall/ProtectedRun will execute hooks without interruptions. If a hook returns a value or encounters an error, it will not halt the execution of the remaining hooks.
These functions are particularly useful for hooks that do not expect a return value, such as Initialize hooks.
Many poorly designed addons in the workshop return values within critical hooks, making it difficult to track down what is preventing a hook from working correctly or causing issues.

Here is a simple list of hooks that could benefit from it:
GM:PreGamemodeLoaded
GM:OnGamemodeLoaded
GM:PostGamemodeLoaded
GM:Initialize
GM:OnEntityCreated
GM:EntityRemoved
GM:InitPostEntity

@robotboy655 robotboy655 added the Addition The pull request adds new functionality. label Jan 17, 2025
@Aws0mee
Copy link
Copy Markdown
Contributor

Aws0mee commented Feb 15, 2025

Would be very nice to avoid some random workshop script breaking servers when it causes a minor error in an initialization hook.

@Winkarst-cpu Winkarst-cpu mentioned this pull request Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Addition The pull request adds new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants