Skip to content

Executing abort() function leads to the Unexpected error #202

Description

@oleua

Hi! I have updated my NC instance to v.34.0.2. Now my simple scripts (eg Directory tree generation) shows Unexpected error when the abort function is run.

eg:

if( exists(out_folder, "tree.txt") )then
	abort("The file 'tree.txt' already exists in this folder.")
end

will lead to

{"reqId":"raRCLIDGVZqSrKgNSl1G","level":3,"time":"2026-08-09T14:17:14+03:00","remoteAddr":"****","user":"username","app":"files_scripts","method":"POST","url":"/index.php/apps/files_scripts/run/3","scriptName":"/index.php","message":"File scripts runtime error","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36","version":"34.0.2.1","data":{"app":"files_scripts","error_message":"The file 'tree.txt' already exists in this folder.","trace":"#0 /www/html/nextcloud-dev-34/apps/files_scripts/lib/Interpreter/Lua/LuaInterpreter.php(14): Lua->eval()\n#1 /www/html/nextcloud-dev-34/apps/files_scripts/lib/Interpreter/Interpreter.php(32): OCA\\FilesScripts\\Interpreter\\Lua\\LuaInterpreter->eval()\n#2 /www/html/nextcloud-dev-34/apps/files_scripts/lib/Service/ScriptService.php(88): OCA\\FilesScripts\\Interpreter\\Interpreter->execute()\n#3 /www/html/nextcloud-dev-34/apps/files_scripts/lib/Controller/ScriptController.php(204): OCA\\FilesScripts\\Service\\ScriptService->runScript()\n#4 /www/html/nextcloud-dev-34/lib/private/AppFramework/Http/Dispatcher.php(165): OCA\\FilesScripts\\Controller\\ScriptController->run()\n#5 /www/html/nextcloud-dev-34/lib/private/AppFramework/Http/Dispatcher.php(78): OC\\AppFramework\\Http\\Dispatcher->executeController()\n#6 /www/html/nextcloud-dev-34/lib/private/AppFramework/App.php(137): OC\\AppFramework\\Http\\Dispatcher->dispatch()\n#7 /www/html/nextcloud-dev-34/lib/private/Route/Router.php(324): OC\\AppFramework\\App::main()\n#8 /www/html/nextcloud-dev-34/lib/base.php(1172): OC\\Route\\Router->match()\n#9 /www/html/nextcloud-dev-34/index.php(25): OC::handleRequest()\n#10 {main}","script_id":"3","inputs":"[]","files":"{\"1\":\"/master/files/new.docx\"}"},"id":"6a7a3d8562d80"}

And I will see pop-up Unexpected Error.

Though the script works.

I tried to modify the file lib/Controller/ScriptController.php without any success:

try {
			$this->scriptService->runScript($script, $context);
		} catch (AbortException $e) {
			return new JSONResponse([
				'error' => $e->getMessage(),
				'messages' => $context->getMessages()
			], HTTP::STATUS_BAD_REQUEST);
		}

The only workaround is to use the construction:

if( exists(out_folder, "tree.txt") )then
	add_message("The file 'tree.txt' already exists in this folder.","error")
else
    new_file(out_folder, "tree.txt", list)
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions