Skip to content

Commit 59aebdd

Browse files
committed
Send correct exception type on error
1 parent b12acc2 commit 59aebdd

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎ProcessMaker/Http/Controllers/Api/ScriptController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function preview(Request $request, Script $script)
130130
$config = json_decode($request->get('config'), true) ?: [];
131131
$code = $request->get('code');
132132

133-
TestScript::dispatch($script, $code, $data, $config);
133+
TestScript::dispatch($script, $request->user(), $code, $data, $config);
134134
return ['status' => 'success'];
135135
}
136136

‎ProcessMaker/Jobs/TestScript.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TestScript implements ShouldQueue
2020
SerializesModels;
2121

2222
protected $script;
23+
protected $current_user;
2324
protected $code;
2425
protected $data;
2526
protected $configuration;
@@ -28,13 +29,15 @@ class TestScript implements ShouldQueue
2829
* Create a new job instance to execute a script.
2930
*
3031
* @param ProcessMaker\Models\Script $script
32+
* @param ProcessMaker\Models\User $current_user
3133
* @param string $code
3234
* @param array $data
3335
* @param array $configuration
3436
*/
35-
public function __construct($script, $code, array $data, array $configuration)
37+
public function __construct(Script $script, User $current_user, $code, array $data, array $configuration)
3638
{
3739
$this->script = $script;
40+
$this->current_user = $current_user;
3841
$this->code = $code;
3942
$this->data = $data;
4043
$this->configuration = $configuration;
@@ -68,6 +71,6 @@ public function handle()
6871
*/
6972
private function sendResponse($status, array $response)
7073
{
71-
$this->script->runAsUser->notify(new ScriptResponseNotification($status, $response));
74+
$this->current_user->notify(new ScriptResponseNotification($status, $response));
7275
}
7376
}

‎ProcessMaker/Models/ScriptDockerBindingFilesTrait.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ProcessMaker\Models;
44

55
use Log;
6+
use ProcessMaker\Exception\ScriptException;
67
use ProcessMaker\Exception\ScriptTimeoutException;
78

89
/**
@@ -78,11 +79,10 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
7879
if ($returnCode) {
7980
if ($returnCode == 137) {
8081
Log::error('Script timed out');
81-
} else {
82-
Log::error('Script threw return code ' . $returnCode);
82+
throw new ScriptTimeoutException(implode("\n", $output));
8383
}
84-
85-
throw new ScriptTimeoutException(implode("\n", $output));
84+
Log::error('Script threw return code ' . $returnCode . 'Message: ' . implode("\n", $output));
85+
throw new ScriptException(implode("\n", $output));
8686
}
8787
$outputs = $this->getOutputFilesContent();
8888
$this->removeTemporalFiles();

‎ProcessMaker/Models/ScriptDockerCopyingFilesTrait.php‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ private function startContainer($container, $timeout)
147147
if ($returnCode) {
148148
if ($returnCode == 137) {
149149
Log::error('Script timed out');
150-
} else {
151-
Log::error('Script threw return code ' . $returnCode);
150+
throw new ScriptTimeoutException(implode("\n", $output));
152151
}
153-
154-
throw new ScriptTimeoutException(implode("\n", $output));
152+
Log::error('Script threw return code ' . $returnCode);
153+
throw new ScriptException(implode("\n", $output));
155154
}
156155
return compact('line', 'output', 'returnCode');
157156
}

0 commit comments

Comments
 (0)