hazel - applescript empty trash raising exception

I have an issue with the following AppleScript with hazel. For testing purposes I made rule that when name contains "test" move to the trash and execute the following AppleScript. Why does it raise an exception? The AS runs fine in the script editor.
Rule

Log
Rule

- Code: Select all
tell application "Finder"
set warns before emptying of trash to false
empty trash
end tell
Log
- Code: Select all
2025-02-03 03:07:53.600 hazelworker[2777] test2: Rule Delete Trash matched.
2025-02-03 03:07:53.617 hazelworker[2777] [File Event] File moved: test2 moved from folder /Users/<USERNAME>/Desktop/untitled folder to folder /Users/<USERNAME>/.Trash.
2025-02-03 03:07:53.642 hazelworker[2777] Could not generate new bookmark data for path /Users/<USERNAME>/Desktop/untitled folder/test2: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist."
2025-02-03 03:07:53.642 hazelworker[2777] Could not create file alias for path /Users/<USERNAME>/Desktop/untitled folder/test2. Error creating bookmark data: (null)
2025-02-03 03:07:53.642 hazelworker[2777] Caught exception in rule evaluation of file test2: *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
2025-02-03 03:07:53.642 hazelworker[2777] ###Arch: x86_64
2025-02-03 03:07:53.642 hazelworker[2777] ###main load address: 0x1075a4000
2025-02-03 03:07:53.642 hazelworker[2777] ###Hazel Core load address: 0x10786c000
2025-02-03 03:07:53.642 hazelworker[2777] ###Noodle load address: 0x107b6e000
2025-02-03 03:07:53.643 hazelworker[2777] ###CK load address: 0x10775a000
2025-02-03 03:07:53.643 hazelworker[2777] (
0 CoreFoundation 0x00007ff8065dc6e3 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80633c8bb objc_exception_throw + 48
2 CoreFoundation 0x00007ff806697f5c _CFThrowFormattedException + 202
3 CoreFoundation 0x00007ff806695ee1 -[__NSPlaceholderArray initWithCapacity:].cold.1 + 0
4 CoreFoundation 0x00007ff8064e5011 -[__NSPlaceholderArray initWithObjects:count:] + 154
5 CoreFoundation 0x00007ff80653e29c +[NSArray arrayWithObjects:count:] + 40
6 HazelCore 0x00000001078b164e errorFromOSAScriptErrorDict + 161807
7 HazelCore 0x000000010789f570 errorFromOSAScriptErrorDict + 87857
8 hazelworker 0x00000001075aa926 hazelworker + 26918
9 hazelworker 0x00000001075ad315 hazelworker + 37653
10 hazelworker 0x00000001075af738 hazelworker + 46904
11 dyld 0x0000000113ac452e start + 462
)
2025-02-03 03:07:54.654 hazelworker[2780] Running worker (v5.3.6) for folder with identifier: trash.
2025-02-03 03:07:54.655 hazelworker[2780] ###Arch: x86_64
2025-02-03 03:07:54.655 hazelworker[2780] ###main load address: 0x10eae8000
2025-02-03 03:07:54.655 hazelworker[2780] ###Hazel Core load address: 0x10edb0000
2025-02-03 03:07:54.655 hazelworker[2780] ###Noodle load address: 0x10f0b2000
2025-02-03 03:07:54.655 hazelworker[2780] ###CK load address: 0x10ec9e000
2025-02-03 03:07:54.691 hazelworker[2780] Processing folder Trash
2025-02-03 03:07:55.654 hazelworker[2777] Done processing folder untitled folder
2025-02-03 03:07:55.719 hazelworker[2780] Done processing folder Trash