mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00

* Improve error information With this commit errors that are raised with zcx_abapgit_exception=>raise and issued with message are enriched with two additional functions. 1) Go to source Navigates to the source code position where zcx_abapgit_exception=>raise is called 2) Callstack Shows a popup with the full callstack and the possibility to navigate to the source of each line with double click This feature requires the full abapGit repository. Without nothing changes. * issue messages directly * zcx_abapgit_exception: adapt callstack handling - callstack as attribute - export callstack to ABAP memory only when SAPGui is available * rename memory id * Add comment why we don't delete callstack from MEM * cleanup * first try html error display * add some comments * add longtext * goto_source and callstack implemented * part 2 * remove * fix * add close button * fix long classname * fix linter * add jump to SE91 * fix lintmr * fix and cleanup * fix linter * fix linter * fix eslint * fix linter * remove message class * remove superfluous constant * add missing method implementation * refactor * add hotkey for message longtext toggling * hotkey 2 * refactor + resize callstack popup * Refactoring: simplify control flow * fix goto callstack for merged abapGit * refactor: simplify control flow * Refactoring: introduce message helper * fix linter * remove TODO pragmas * ren. render meth + move zcl_abapgit_gui_chunk_lib * refactoring: simplify control flow * simplify exception handling * refactor * refactor * refactor * remove duplication * Rename method * rename method * remove superfluous constant * call ZCL_ABAPGIT_MESSAGE_HELPER dynamically * cleanup * Improve UX * fix linter * remove hotkey
234 lines
6.3 KiB
ABAP
234 lines
6.3 KiB
ABAP
"! abapGit general error
|
|
CLASS zcx_abapgit_exception DEFINITION
|
|
PUBLIC
|
|
INHERITING FROM cx_static_check
|
|
CREATE PUBLIC.
|
|
|
|
PUBLIC SECTION.
|
|
INTERFACES if_t100_message.
|
|
|
|
DATA subrc TYPE sysubrc READ-ONLY.
|
|
DATA msgv1 TYPE symsgv READ-ONLY.
|
|
DATA msgv2 TYPE symsgv READ-ONLY.
|
|
DATA msgv3 TYPE symsgv READ-ONLY.
|
|
DATA msgv4 TYPE symsgv READ-ONLY.
|
|
DATA mt_callstack TYPE abap_callstack READ-ONLY.
|
|
|
|
"! Raise exception with text
|
|
"! @parameter iv_text | Text
|
|
"! @parameter ix_previous | Previous exception
|
|
"! @raising zcx_abapgit_exception | Exception
|
|
CLASS-METHODS raise
|
|
IMPORTING
|
|
!iv_text TYPE clike
|
|
!ix_previous TYPE REF TO cx_root OPTIONAL
|
|
RAISING
|
|
zcx_abapgit_exception.
|
|
"! Raise exception with T100 message
|
|
"! <p>
|
|
"! Will default to sy-msg* variables. These need to be set right before calling this method.
|
|
"! </p>
|
|
"! @parameter iv_msgid | Message ID
|
|
"! @parameter iv_msgno | Message number
|
|
"! @parameter iv_msgv1 | Message variable 1
|
|
"! @parameter iv_msgv2 | Message variable 2
|
|
"! @parameter iv_msgv3 | Message variable 3
|
|
"! @parameter iv_msgv4 | Message variable 4
|
|
"! @raising zcx_abapgit_exception | Exception
|
|
CLASS-METHODS raise_t100
|
|
IMPORTING
|
|
VALUE(iv_msgid) TYPE symsgid DEFAULT sy-msgid
|
|
VALUE(iv_msgno) TYPE symsgno DEFAULT sy-msgno
|
|
VALUE(iv_msgv1) TYPE symsgv DEFAULT sy-msgv1
|
|
VALUE(iv_msgv2) TYPE symsgv DEFAULT sy-msgv2
|
|
VALUE(iv_msgv3) TYPE symsgv DEFAULT sy-msgv3
|
|
VALUE(iv_msgv4) TYPE symsgv DEFAULT sy-msgv4
|
|
RAISING
|
|
zcx_abapgit_exception.
|
|
METHODS constructor
|
|
IMPORTING
|
|
!textid LIKE if_t100_message=>t100key OPTIONAL
|
|
!previous LIKE previous OPTIONAL
|
|
!msgv1 TYPE symsgv OPTIONAL
|
|
!msgv2 TYPE symsgv OPTIONAL
|
|
!msgv3 TYPE symsgv OPTIONAL
|
|
!msgv4 TYPE symsgv OPTIONAL.
|
|
METHODS get_longtext REDEFINITION.
|
|
METHODS get_source_position REDEFINITION.
|
|
PROTECTED SECTION.
|
|
PRIVATE SECTION.
|
|
CONSTANTS:
|
|
gc_generic_error_msg TYPE string VALUE `An error occured (ZCX_ABAPGIT_EXCEPTION)` ##NO_TEXT.
|
|
|
|
METHODS:
|
|
save_callstack.
|
|
|
|
ENDCLASS.
|
|
|
|
|
|
|
|
CLASS zcx_abapgit_exception IMPLEMENTATION.
|
|
|
|
|
|
METHOD constructor ##ADT_SUPPRESS_GENERATION.
|
|
super->constructor( previous = previous ).
|
|
|
|
me->msgv1 = msgv1.
|
|
me->msgv2 = msgv2.
|
|
me->msgv3 = msgv3.
|
|
me->msgv4 = msgv4.
|
|
|
|
CLEAR me->textid.
|
|
IF textid IS INITIAL.
|
|
if_t100_message~t100key = if_t100_message=>default_textid.
|
|
ELSE.
|
|
if_t100_message~t100key = textid.
|
|
ENDIF.
|
|
|
|
save_callstack( ).
|
|
|
|
ENDMETHOD.
|
|
|
|
|
|
METHOD get_longtext.
|
|
|
|
" You should remember that we have to call ZCL_ABAPGIT_MESSAGE_HELPER
|
|
" dynamically, because the compiled abapGit report puts the definition
|
|
" of the exception classes on the top and therefore ZCL_ABAPGIT_MESSAGE_HELPER
|
|
" isn't statically known
|
|
|
|
DATA: lo_message_helper TYPE REF TO object.
|
|
|
|
result = super->get_longtext( ).
|
|
|
|
IF if_t100_message~t100key IS NOT INITIAL.
|
|
|
|
CREATE OBJECT lo_message_helper TYPE ('ZCL_ABAPGIT_MESSAGE_HELPER')
|
|
EXPORTING
|
|
ii_t100_message = me.
|
|
|
|
CALL METHOD lo_message_helper->('GET_T100_LONGTEXT')
|
|
RECEIVING
|
|
rv_longtext = result.
|
|
|
|
ENDIF.
|
|
|
|
ENDMETHOD.
|
|
|
|
|
|
METHOD raise.
|
|
DATA: lv_msgv1 TYPE symsgv,
|
|
lv_msgv2 TYPE symsgv,
|
|
lv_msgv3 TYPE symsgv,
|
|
lv_msgv4 TYPE symsgv,
|
|
ls_t100_key TYPE scx_t100key,
|
|
lv_text TYPE string.
|
|
|
|
IF iv_text IS INITIAL.
|
|
lv_text = gc_generic_error_msg.
|
|
ELSE.
|
|
lv_text = iv_text.
|
|
ENDIF.
|
|
|
|
CALL METHOD ('ZCL_ABAPGIT_MESSAGE_HELPER')=>set_msg_vars_for_clike
|
|
EXPORTING
|
|
iv_text = lv_text.
|
|
|
|
ls_t100_key-msgid = sy-msgid.
|
|
ls_t100_key-msgno = sy-msgno.
|
|
ls_t100_key-attr1 = 'MSGV1'.
|
|
ls_t100_key-attr2 = 'MSGV2'.
|
|
ls_t100_key-attr3 = 'MSGV3'.
|
|
ls_t100_key-attr4 = 'MSGV4'.
|
|
lv_msgv1 = sy-msgv1.
|
|
lv_msgv2 = sy-msgv2.
|
|
lv_msgv3 = sy-msgv3.
|
|
lv_msgv4 = sy-msgv4.
|
|
|
|
RAISE EXCEPTION TYPE zcx_abapgit_exception
|
|
EXPORTING
|
|
textid = ls_t100_key
|
|
msgv1 = lv_msgv1
|
|
msgv2 = lv_msgv2
|
|
msgv3 = lv_msgv3
|
|
msgv4 = lv_msgv4
|
|
previous = ix_previous.
|
|
ENDMETHOD.
|
|
|
|
|
|
METHOD raise_t100.
|
|
DATA: ls_t100_key TYPE scx_t100key.
|
|
|
|
ls_t100_key-msgid = iv_msgid.
|
|
ls_t100_key-msgno = iv_msgno.
|
|
ls_t100_key-attr1 = 'MSGV1'.
|
|
ls_t100_key-attr2 = 'MSGV2'.
|
|
ls_t100_key-attr3 = 'MSGV3'.
|
|
ls_t100_key-attr4 = 'MSGV4'.
|
|
|
|
IF iv_msgid IS INITIAL.
|
|
CLEAR ls_t100_key.
|
|
ENDIF.
|
|
|
|
RAISE EXCEPTION TYPE zcx_abapgit_exception
|
|
EXPORTING
|
|
textid = ls_t100_key
|
|
msgv1 = iv_msgv1
|
|
msgv2 = iv_msgv2
|
|
msgv3 = iv_msgv3
|
|
msgv4 = iv_msgv4.
|
|
ENDMETHOD.
|
|
|
|
|
|
METHOD save_callstack.
|
|
|
|
FIELD-SYMBOLS: <ls_callstack> TYPE abap_callstack_line.
|
|
|
|
CALL FUNCTION 'SYSTEM_CALLSTACK'
|
|
IMPORTING
|
|
callstack = mt_callstack.
|
|
|
|
" You should remember that the first lines are from zcx_abapgit_exception
|
|
" and are removed so that highest level in the callstack is the position where
|
|
" the exception is raised.
|
|
"
|
|
" For the merged report it's hard to do that, because zcx_abapgit_exception
|
|
" isn't visible in the callstack. Therefore we have to check the Events.
|
|
LOOP AT mt_callstack ASSIGNING <ls_callstack>.
|
|
|
|
IF <ls_callstack>-mainprogram CP |ZCX_ABAPGIT_EXCEPTION*| " full
|
|
OR <ls_callstack>-blockname = `SAVE_CALLSTACK` " merged
|
|
OR <ls_callstack>-blockname = `CONSTRUCTOR` " merged
|
|
OR <ls_callstack>-blockname CP `RAISE*`. "merged
|
|
DELETE TABLE mt_callstack FROM <ls_callstack>.
|
|
ELSE.
|
|
EXIT.
|
|
ENDIF.
|
|
|
|
ENDLOOP.
|
|
|
|
ENDMETHOD.
|
|
|
|
|
|
METHOD get_source_position.
|
|
|
|
FIELD-SYMBOLS: <ls_callstack> TYPE abap_callstack_line.
|
|
|
|
READ TABLE mt_callstack ASSIGNING <ls_callstack>
|
|
INDEX 1.
|
|
IF sy-subrc = 0.
|
|
program_name = <ls_callstack>-mainprogram.
|
|
include_name = <ls_callstack>-include.
|
|
source_line = <ls_callstack>-line.
|
|
ELSE.
|
|
super->get_source_position(
|
|
IMPORTING
|
|
program_name = program_name
|
|
include_name = include_name
|
|
source_line = source_line ).
|
|
ENDIF.
|
|
|
|
ENDMETHOD.
|
|
|
|
ENDCLASS.
|