View Issue Details

IDProjectCategoryView StatusLast Update
0021661mantisbtcode cleanuppublic2018-03-05 10:44
Reportercproensa Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version1.3.2 
Summary0021661: throw errors as exceptions

Error handling is currently done with PHP error triggering, which is handled in error_api.
There should be a way to throw errors as exceptions. This would allow a more flexible handling of error conditions.

For example: In bug-action-group, if any operation in the list of bugs fails, the whole task is stopped. By using try-catch, any error for an individual bug operation can be managed and shown to the user at the ending report.

A proposal is to set up an error handling mode that throws exception instead of showing the current error page. This mode can be switched on and off, when exception-aware code is going to be used.

TagsNo tags attached.


related to 0021595 new When a filter generates a bad query, reset the filter 




2016-09-04 09:15

developer   ~0053933

@cproensa, you might be interested in having a look at a branch which has been removed some while ago.
It can still be found on older forks e.g.
Unfortunately all those changes did not make their way to master branch.



2016-09-04 13:14

developer   ~0053936

I see there is doing a full refactor to exception handling.
My suggestion is more simple, as a start.

@atrol see this proof of concept, applied to bug_actiongroup



2016-09-05 02:52

manager   ~0053937

I'm on board with moving towards exceptions. I would appreciate a solution that achieves the following:

  • Implement this incrementally while shipping releases.
  • Make it clear when calling an API whether we are using exceptions or old model. Rather than having to guess.
  • Reduce boiler plate code that we have to write for each entity we manage in Mantis.

I suggest a slow refactor where we have classes for our entities that does the ORM + exceptions. Then have the existing APIs provide the same behavior over such classes until they are no longer needed.

We can then use these model classes as the foundation for our SOAP/REST API as well as our regular web page calls.

Examples of such gradual refactoring including introduction of classes like MantisEnum, though it doesn't involve DB access.



2016-09-05 14:24

developer   ~0053950

vboctor, that is a very long term goal, at current progression.

Have a look at my proposal, which is a more short term idea:

  • Create a generic exception class, which is a container for a mantis error.
  • When requested, error_api will throw this exception when handling any error.
  • This handling would be switched on on those parts of mantis that need to manage errors instead of current error page (avoiding execution stop).

(This exception class could be improved in the future as the parent of specific exceptions. But that is another story, as you suggested.)

Think of it like the facility we currently have for error handling that bypasses ui and outputs HTTP error header.

I see direct application:

  • manage bug_actiongroup operations.
  • handle file upload errors on bug_report


2018-03-05 10:40

reporter   ~0059088

Last edited: 2018-03-05 10:44

View 2 revisions

Adding here something related


            $t_stack = error_stack_trace();
            if( isset( $t_stack[2] ) ) {
                $t_caller = $t_stack[2];
            } else {
                # If called from main page body, there is no stack block for the funcion, use the page block instead
                $t_caller = $t_stack[1];

# -------------------------------------
# Needed because sometimes (unfortunately do not know when) both keys are missing
# file, line
            if( !isset($t_caller['file']) ) {
                $t_caller['file'] = '';

            if( !isset($t_caller['line']) ) {
                $t_caller['line'] = '';
# --------------------------------------------------------

EDIT: fix markdown

Issue History

Date Modified Username Field Change
2016-09-03 20:40 cproensa New Issue
2016-09-04 09:15 atrol Note Added: 0053933
2016-09-04 13:14 cproensa Note Added: 0053936
2016-09-05 02:52 vboctor Note Added: 0053937
2016-09-05 14:24 cproensa Note Added: 0053950
2017-08-29 23:54 vboctor Relationship added related to 0021595
2018-03-05 10:40 fman Note Added: 0059088
2018-03-05 10:44 dregad Note Edited: 0059088 View Revisions