Skip to content

Commit df5466c

Browse files
Itay4roysagi
andauthored
CommonServerPython - add skip update to return error in get remote data (demisto#12027)
* add skip update to return error in get remote data * add whitespace prefix * check last exception is not notimplemented * fix over indent * Update 1_8_2.md Co-authored-by: roysagi <[email protected]>
1 parent bafeb3c commit df5466c

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

Packs/Base/ReleaseNotes/1_8_5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#### Scripts
3+
##### CommonServerPython
4+
- Improved the error handling in the incoming mirroring flow.

Packs/Base/Scripts/CommonServerPython/CommonServerPython.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,10 +4657,11 @@ def return_error(message, error='', outputs=None):
46574657
:return: Error entry object
46584658
:rtype: ``dict``
46594659
"""
4660-
is_server_handled = hasattr(demisto, 'command') and demisto.command() in ('fetch-incidents',
4661-
'fetch-credentials',
4662-
'long-running-execution',
4663-
'fetch-indicators')
4660+
is_command = hasattr(demisto, 'command')
4661+
is_server_handled = is_command and demisto.command() in ('fetch-incidents',
4662+
'fetch-credentials',
4663+
'long-running-execution',
4664+
'fetch-indicators')
46644665
if is_debug_mode() and not is_server_handled and any(sys.exc_info()): # Checking that an exception occurred
46654666
message = "{}\n\n{}".format(message, traceback.format_exc())
46664667

@@ -4672,6 +4673,10 @@ def return_error(message, error='', outputs=None):
46724673
if not isinstance(message, str):
46734674
message = message.encode('utf8') if hasattr(message, 'encode') else str(message)
46744675

4676+
if is_command and demisto.command() == 'get-modified-remote-data':
4677+
if (error and not isinstance(error, NotImplementedError)) or sys.exc_info()[0] != NotImplementedError:
4678+
message = 'skip update. error: ' + message
4679+
46754680
if is_server_handled:
46764681
raise Exception(message)
46774682
else:

Packs/Base/Scripts/CommonServerPython/CommonServerPython_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,29 @@ def test_exception_in_return_error(mocker):
10991099
assert IntegrationLogger.__call__.call_count == 2
11001100

11011101

1102+
def test_return_error_get_modified_remote_data(mocker):
1103+
from CommonServerPython import return_error
1104+
mocker.patch.object(demisto, 'command', return_value='get-modified-remote-data')
1105+
mocker.patch.object(demisto, 'results')
1106+
err_msg = 'Test Error'
1107+
with raises(SystemExit):
1108+
return_error(err_msg)
1109+
assert demisto.results.call_args[0][0]['Contents'] == 'skip update. error: ' + err_msg
1110+
1111+
1112+
def test_return_error_get_modified_remote_data_not_implemented(mocker):
1113+
from CommonServerPython import return_error
1114+
mocker.patch.object(demisto, 'command', return_value='get-modified-remote-data')
1115+
mocker.patch.object(demisto, 'results')
1116+
err_msg = 'Test Error'
1117+
with raises(SystemExit):
1118+
try:
1119+
raise NotImplementedError('Command not implemented')
1120+
except:
1121+
return_error(err_msg)
1122+
assert demisto.results.call_args[0][0]['Contents'] == err_msg
1123+
1124+
11021125
def test_get_demisto_version(mocker, clear_version_cache):
11031126
# verify expected server version and build returned in case Demisto class has attribute demistoVersion
11041127
mocker.patch.object(

Packs/Base/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Base",
33
"description": "The base pack for Cortex XSOAR.",
44
"support": "xsoar",
5-
"currentVersion": "1.8.4",
5+
"currentVersion": "1.8.5",
66
"author": "Cortex XSOAR",
77
"serverMinVersion": "6.0.0",
88
"url": "https://www.paloaltonetworks.com/cortex",

0 commit comments

Comments
 (0)