5050use OCP \TaskProcessing \Exception \NotFoundException ;
5151use OCP \TaskProcessing \Exception \ProcessingException ;
5252use OCP \TaskProcessing \Exception \UnauthorizedException ;
53+ use OCP \TaskProcessing \Exception \UserFacingProcessingException ;
5354use OCP \TaskProcessing \Exception \ValidationException ;
5455use OCP \TaskProcessing \IInternalTaskType ;
5556use OCP \TaskProcessing \IManager ;
@@ -211,7 +212,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
211212 try {
212213 return ['output ' => $ this ->provider ->process ($ input ['input ' ])];
213214 } catch (\RuntimeException $ e ) {
214- throw new ProcessingException ($ e ->getMessage (), 0 , $ e );
215+ throw new ProcessingException ($ e ->getMessage (), previous: $ e );
215216 }
216217 }
217218
@@ -362,7 +363,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
362363 try {
363364 $ this ->provider ->generate ($ input ['input ' ], $ resources );
364365 } catch (\RuntimeException $ e ) {
365- throw new ProcessingException ($ e ->getMessage (), 0 , $ e );
366+ throw new ProcessingException ($ e ->getMessage (), previous: $ e );
366367 }
367368 for ($ i = 0 ; $ i < $ input ['numberOfImages ' ]; $ i ++) {
368369 if (is_resource ($ resources [$ i ])) {
@@ -480,7 +481,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
480481 try {
481482 $ result = $ this ->provider ->transcribeFile ($ input ['input ' ]);
482483 } catch (\RuntimeException $ e ) {
483- throw new ProcessingException ($ e ->getMessage (), 0 , $ e );
484+ throw new ProcessingException ($ e ->getMessage (), previous: $ e );
484485 }
485486 return ['output ' => $ result ];
486487 }
@@ -1041,7 +1042,8 @@ public function processTask(Task $task, ISynchronousProvider $provider): bool {
10411042 $ output = $ provider ->process ($ task ->getUserId (), $ input , fn (float $ progress ) => $ this ->setTaskProgress ($ task ->getId (), $ progress ));
10421043 } catch (ProcessingException $ e ) {
10431044 $ this ->logger ->warning ('Failed to process a TaskProcessing task with synchronous provider ' . $ provider ->getId (), ['exception ' => $ e ]);
1044- $ this ->setTaskResult ($ task ->getId (), $ e ->getMessage (), null );
1045+ $ userFacingErrorMessage = $ e instanceof UserFacingProcessingException ? $ e ->getUserFacingMessage () : null ;
1046+ $ this ->setTaskResult ($ task ->getId (), $ e ->getMessage (), null , userFacingError: $ userFacingErrorMessage );
10451047 return false ;
10461048 } catch (\Throwable $ e ) {
10471049 $ this ->logger ->error ('Unknown error while processing TaskProcessing task ' , ['exception ' => $ e ]);
@@ -1112,7 +1114,7 @@ public function setTaskProgress(int $id, float $progress): bool {
11121114 return true ;
11131115 }
11141116
1115- public function setTaskResult (int $ id , ?string $ error , ?array $ result , bool $ isUsingFileIds = false ): void {
1117+ public function setTaskResult (int $ id , ?string $ error , ?array $ result , bool $ isUsingFileIds = false , ? string $ userFacingError = null ): void {
11161118 // TODO: Not sure if we should rather catch the exceptions of getTask here and fail silently
11171119 $ task = $ this ->getTask ($ id );
11181120 if ($ task ->getStatus () === Task::STATUS_CANCELLED ) {
@@ -1122,8 +1124,12 @@ public function setTaskResult(int $id, ?string $error, ?array $result, bool $isU
11221124 if ($ error !== null ) {
11231125 $ task ->setStatus (Task::STATUS_FAILED );
11241126 $ task ->setEndedAt (time ());
1125- // truncate error message to 1000 characters
1126- $ task ->setErrorMessage (mb_substr ($ error , 0 , 1000 ));
1127+ // truncate error message to 4000 characters
1128+ $ task ->setErrorMessage (substr ($ error , 0 , 4000 ));
1129+ // truncate error message to 4000 characters
1130+ if ($ userFacingError !== null ) {
1131+ $ task ->setUserFacingErrorMessage (substr ($ userFacingError , 0 , 4000 ));
1132+ }
11271133 $ this ->logger ->warning ('A TaskProcessing ' . $ task ->getTaskTypeId () . ' task with id ' . $ id . ' failed with the following message: ' . $ error );
11281134 } elseif ($ result !== null ) {
11291135 $ taskTypes = $ this ->getAvailableTaskTypes ();
0 commit comments