Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackgroundWorkWindow affects how exceptions from background task are handled #2520

Open
dkz opened this issue Oct 31, 2019 · 3 comments
Open
Assignees
Labels
state: won't fix This will not be worked on type: bug Something isn't working
Milestone

Comments

@dkz
Copy link
Contributor

dkz commented Oct 31, 2019

Environment

  • Platform version: 6.10.13

Description of the bug or enhancement

BackgroundWorkWindow wraps tasks with com.haulmont.cuba.gui.backgroundwork.LocalizedTaskWrapper which completely disregards com.haulmont.cuba.web.exception.ExceptionHandlers: exception is reported immediately despite the fact it can have exception handlers registered in the app.

Expected behavior

Sample A.

AppBeans.get(BackgroundWorker.class)
    .handle(new VerificationTask(authRequest, validationContext))
    .execute();

underlying task does getDsContext().commit() and violates unique constraint.
As a result a message is shown to user with appropriate localized constrain violation string, i.e. "Job with the same contract number already exists".

Actual behavior

Sample B, this sample should be equivalent to the A in terms of exception handling:

BackgroundWorkWindow.show(new VerificationTask(authRequest, validationContext),
    getMessage("creditCard.verificationBgTask.title"),
    getMessage("creditCard.bgTransaction.message"), false);

actually: underlying task does getDsContext().commit() and after constraint violation a "Report an exception" dialog is shown with an exception stack trace.

@knstvk knstvk added the type: bug Something isn't working label Nov 5, 2019
@knstvk knstvk assigned Flaurite and unassigned t1-cuba Nov 5, 2019
@knstvk knstvk added this to the Release 6.10 milestone Nov 11, 2019
@Flaurite
Copy link
Contributor

Flaurite commented Nov 12, 2019

Hi @dkz! Unfortunately, I cannot reproduce the issue. Do you use BackgroundTask#handleException() for handling exception in the UI thread? Please, try this example: demo.zip

@dkz
Copy link
Contributor Author

dkz commented Nov 13, 2019

Hi @Flaurite,
Sorry, there is an important detail I missed in original ticket description: commit happens in done() method. Thus my complaint in regard of LocalizedTaskWrapper is directed towards implementation of done() and cancelled() method with try-catch block: exception is caught and is shown in a non-user-friendly fashion in comparison to globally defined application exception handlers.

@Flaurite
Copy link
Contributor

Sorry for the long delay @dkz,
LocalizedTaskWrapper has such default behavior for done() and result() methods to do not miss the exception if it will occur. If we do not show the exception and delegate it to handleException() the lambda in window.closeAndRun() will not be invoked.
In your case, you need to manually handle exception in your done() and result() methods and if it necessary delegate to ExceptionHandlers:

try {
    dataManager.commit(commitContext);
} catch (Exception e) {
    App.getInstance().getExceptionHandlers().handle(new ErrorEvent(e));
}

@Flaurite Flaurite added the state: won't fix This will not be worked on label Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: won't fix This will not be worked on type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants