Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def my_sftc_connection_error(request_context, REQUTEXT):
# depending on the REQUTEXT value, raises errors.
if REQUTEXT == 'EXCEPTION':
raise ABAPApplicationError(key='BAD_EXCEPTION_HAPPENED')
elif REQUTEXT == 'EXCEPTION_MESSAGE':
raise ABAPApplicationError(key='BAD_EXCEPTION_W_MSG',
msg_class='SR', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='007', # 3 char numeric
msg_v1='V1 text' # 50 char
)
elif REQUTEXT == 'MESSAGE':
raise ABAPRuntimeError(
msg_class='SM', # message id or class
msg_type='E', # out of e.g. 'E', 'A' or 'X'
msg_number='107', # 3 char numeric string
msg_v1='V1 text (ABAP_MESSAGE)'
)
elif REQUTEXT == 'FAILURE':
raise ExternalRuntimeError("Something very bad happened.")
elif REQUTEXT == 'INVALID':
raise RFCError("Invalid exception")
return {
'ECHOTEXT': REQUTEXT,
'RESPTEXT': u"Local (raise error) server here. Use the following values"
u"for REQUTEXT: EXCEPTION, EXCEPTION_MESSAGE, MESSAGE, "
def test_RFC_RAISE_ERROR_AbapRuntimeError_A(self):
# cf. ExceptionTest.c (l. 112ff)
try:
self.conn.call("RFC_RAISE_ERROR", MESSAGETYPE="A")
except (pyrfc.ABAPRuntimeError) as ex:
assert self.conn.alive == True
error = get_error(ex)
assert error["code"] == 4
assert error["msg_class"] == "SR"
assert error["msg_type"] == "A"
assert error["msg_number"] == "006"
assert error["msg_v1"] == "Method = 0"
with self.assertRaises(ABAPApplicationError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION")
self.assertEqual(run.exception.code, 5, "rc")
self.assertEqual(run.exception.key, "BAD_EXCEPTION_HAPPENED")
with self.assertRaises(ABAPApplicationError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="EXCEPTION_MESSAGE")
self.assertEqual(run.exception.code, 5, "rc")
self.assertEqual(run.exception.key, "BAD_EXCEPTION_W_MSG")
self.assertEqual(run.exception.msg_class, "SR")
self.assertEqual(run.exception.msg_type, "E")
self.assertEqual(run.exception.msg_number, "007")
self.assertEqual(run.exception.msg_v1, "V1 text")
with self.assertRaises(ABAPRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="MESSAGE")
self.assertEqual(run.exception.code, 4, "rc")
self.assertEqual(run.exception.msg_class, "SM")
self.assertEqual(run.exception.msg_type, "E")
self.assertEqual(run.exception.msg_number, "107")
self.assertEqual(run.exception.msg_v1, "V1 text (ABAP_MESSAGE)")
with self.assertRaises(ExternalRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="FAILURE")
self.assertEqual(run.exception.code, 15, "rc")
self.assertEqual(run.exception.message[:9], "Something")
with self.assertRaises(ExternalRuntimeError) as run:
test.invoke_srv_function("STFC_CONNECTION", REQUTEXT="INVALID")
self.assertEqual(run.exception.code, 15, "rc")
self.assertEqual(run.exception.message[:7], "Invalid")
try:
self.conn.call("RFC_RAISE_ERROR", MESSAGETYPE="X")
except (pyrfc.ABAPRuntimeError) as ex:
error = get_error(ex)
assert error["code"] == 4
assert error["key"] == "MESSAGE_TYPE_X"
assert error["msg_class"] == "00"
assert error["msg_type"] == "X"
assert error["msg_number"] == "341"
assert error["msg_v1"] == "MESSAGE_TYPE_X"
self.conn.call("RFC_PING")
# '36_E': 'ABAPRuntimeError-4-Division by 0 (type I)-Division by 0 (type I)-True''] ==
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="36", MESSAGETYPE="E")
except (pyrfc.ABAPRuntimeError) as ex:
error = get_error(ex)
assert error["code"] == 4
assert u"Division by 0" in error["message"][0]
self.conn.call("RFC_PING")
# '3_E': 'ABAPRuntimeError-3-COMPUTE_INT_ZERODIVIDE-Division by 0 (type I)-True''] ==
# cf. ExceptionTest.c (l. 164ff)
try:
self.conn.call("RFC_RAISE_ERROR", METHOD="3", MESSAGETYPE="E")
except (pyrfc.ABAPRuntimeError) as ex:
error = get_error(ex)
assert error["code"] == 3
assert error["key"] == "COMPUTE_INT_ZERODIVIDE"
self.conn.call("RFC_PING")
# '51_E': 'ABAPRuntimeError-3-BLOCKED_COMMIT-A database commit was blocked by the application.-True''] ==
for field_description in type_desc.fields:
for key, width in zip(field_keys, field_widths):
sys.stdout.write(u"{0}".format(field_description[key]).ljust(width) + u" ")
sys.stdout.write(u"\n")
sys.stdout.write(u" " * 4 + u"-----------( Structure of {0.name} )-----------\n".format(type_desc))
sys.stdout.write(u"-" * sum(parameter_widths) + u"\n")
connection.close()
except CommunicationError:
print ("Could not connect to server.")
raise
except LogonError:
print ("Could not log in. Wrong credentials?")
raise
except (ABAPApplicationError, ABAPRuntimeError):
print ("An error occurred.")
raise