Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 32762x 32762x 32762x 32762x 32762x 32762x 32762x 32762x 1x 16384x 16384x 16384x 16384x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 112287x 16384x 16384x 13x 13x 13x 16384x 16384x 15817x 15817x 16384x 16384x 267x 267x 16384x 16384x 330x 330x 330x 1686x 1686x 1686x 1648x 1648x 38x 38x 38x 1686x 7x 7x 1686x 2x 2x 2x 29x 29x 1686x 1686x 1686x 5x 5x 5x 5x 24x 24x 1686x 59x 59x 24x 24x 1686x 1686x 8x 8x 8x 24x 24x 1686x 4x 4x 4x 24x 1686x 4x 8x 8x 3x 3x 3x 8x 4x 1686x 330x 330x 330x 16384x 16384x | import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import * as Statements from "../abap/2_statements/statements";
import * as Expressions from "../abap/2_statements/expressions";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {ExpressionNode} from "../abap/nodes";
export class RFCErrorHandlingConf extends BasicRuleConfig {
/** Also check CALL FUNCTION ... STARTING NEW TASK without DESTINATION, an asynchronous RFC to the destination NONE */
public startingNewTask: boolean = true;
/** Report error_message in the EXCEPTIONS of an RFC call, it is ignored in RFC */
public errorMessage: boolean = true;
/** Report SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE, the error text is lost */
public requireMessage: boolean = false;
}
export class RFCErrorHandling extends ABAPRule {
private conf = new RFCErrorHandlingConf();
public getMetadata(): IRuleMetadata {
return {
key: "rfc_error_handling",
title: "RFC error handling",
tags: [RuleTag.SingleFile],
shortDescription: `Checks that exceptions 'system_failure' and 'communication_failure' are handled in RFC calls`,
extendedInformation: `RESOURCE_FAILURE is also required for asynchronous calls with DESTINATION IN GROUP.
Checked are CALL FUNCTION ... DESTINATION and, with startingNewTask, CALL FUNCTION ... STARTING NEW TASK
without DESTINATION, which is an asynchronous RFC to the destination NONE.
CALL FUNCTION ... IN BACKGROUND TASK is not checked, it cannot have EXCEPTIONS.
errorMessage: reports error_message in the EXCEPTIONS of an RFC call. It is ignored in RFC, a message of
type A, E or X ends the called function module and raises SYSTEM_FAILURE, use system_failure = n MESSAGE msg
to get the message text. Exception: with a DESTINATION that is blank at runtime, the call is local.
requireMessage: reports SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE.
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exception.html
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapcall_function_destination_para.html`,
badExample: `CALL FUNCTION 'ZRFC'
DESTINATION lv_rfc.
CALL FUNCTION 'ZRFC'
STARTING NEW TASK 'TASK'
EXCEPTIONS
error_message = 1
OTHERS = 2.`,
goodExample: `CALL FUNCTION 'ZRFC'
DESTINATION lv_rfc
EXCEPTIONS
system_failure = 1 MESSAGE msg
communication_failure = 2 MESSAGE msg
OTHERS = 3.
CALL FUNCTION 'ZRFC'
STARTING NEW TASK 'TASK'
EXCEPTIONS
system_failure = 1 MESSAGE msg
communication_failure = 2 MESSAGE msg
OTHERS = 3.`,
};
}
private getMessage(requireResourceFailure: boolean): string {
return "RFC error handling: At least one unhandled exception from SYSTEM_FAILURE, COMMUNICATION_FAILURE"
+ (requireResourceFailure ? ", RESOURCE_FAILURE" : "");
}
public getConfig() {
return this.conf;
}
public setConfig(conf: RFCErrorHandlingConf) {
this.conf = conf;
}
public runParsed(file: ABAPFile) {
const output: Issue[] = [];
for (const stat of file.getStatements()) {
const token = stat.getFirstToken();
if (!(stat.get() instanceof Statements.CallFunction)) {
continue;
}
const destination = stat.findFirstExpression(Expressions.Destination);
const starting = stat.findDirectTokenByText("STARTING") !== undefined;
if (destination === undefined && (starting === false || this.conf.startingNewTask === false)) {
continue;
}
if (stat.findDirectTokenByText("BACKGROUND") !== undefined) {
// transactional RFC, it has no EXCEPTIONS
continue;
}
const requireResourceFailure = starting === true
&& destination?.findDirectTokenByText("GROUP") !== undefined;
const list = stat.findFirstExpression(Expressions.ParameterListExceptions);
if (list === undefined) {
const issue = Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
output.push(issue);
continue;
}
const exceptions = new Map<string, ExpressionNode>();
for (const exception of list.findDirectExpressions(Expressions.ParameterException)) {
exceptions.set(exception.getFirstToken().getStr().toUpperCase(), exception);
}
if (exceptions.has("SYSTEM_FAILURE") === false
|| exceptions.has("COMMUNICATION_FAILURE") === false
|| (requireResourceFailure && exceptions.has("RESOURCE_FAILURE") === false)) {
const issue = Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
output.push(issue);
}
const errorMessage = exceptions.get("ERROR_MESSAGE");
if (this.conf.errorMessage !== false && errorMessage !== undefined) {
const message = "error_message is ignored in RFC, messages of type A, E and X raise SYSTEM_FAILURE, use system_failure = n MESSAGE msg";
output.push(Issue.atToken(file, errorMessage.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
}
if (this.conf.requireMessage === true) {
for (const name of ["SYSTEM_FAILURE", "COMMUNICATION_FAILURE"]) {
const exception = exceptions.get(name);
if (exception !== undefined && exception.findDirectTokenByText("MESSAGE") === undefined) {
const message = `${name} without MESSAGE, the error text is lost, use ${name.toLowerCase()} = n MESSAGE msg`;
output.push(Issue.atToken(file, exception.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
}
}
}
}
return output;
}
}
|