Skip to content

Commit a2792c9

Browse files
authored
Merge pull request #4598 from StackStorm/fix_null_filter_unicode_error
Correctly handle exception instances with non-ascii (unicode) error messages
2 parents f067176 + c383843 commit a2792c9

File tree

126 files changed

+850
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+850
-302
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,24 @@ Fixed
5252
* Fix orquesta with items task performance issue. Workflow runtime increase significantly when a
5353
with items task has many items and result in many retries on write conflicts. A distributed lock
5454
is acquired before write operations to avoid write conflicts. (bug fix) Stackstorm/orquesta#125
55+
* Fix a bug with some API endpoints returning 500 internal server error when an exception contained
56+
unicode data. (bug fix) #4598
57+
58+
2.10.4 - March 15, 2019
59+
-----------------------
60+
61+
Fixed
62+
~~~~~
63+
5564
* Fix inadvertent regression in notifier service which would cause generic action trigger to only
5665
be dispatched for completed states even if custom states were specified using
5766
``action_sensor.emit_when`` config option. (bug fix)
5867
Reported by Shu Sugimoto (@shusugmt). #4591
5968
* Make sure we don't log auth token and api key inside st2api log file if those values are provided
6069
via query parameter and not header (``?x-auth-token=foo``, ``?st2-api-key=bar``). (bug fix) #4592
6170
#4589
62-
* Fix rendering of config_context in orquesta task that references action in different pack.
63-
(bug fix) #4570
71+
* Fix rendering of ``{{ config_context. }}`` in orquesta task that references action from a
72+
different pack (bug fix) #4570 #4567
6473
* Add missing default config location (``/etc/st2/st2.conf``) to the following services:
6574
``st2actionrunner``, ``st2scheduler``, ``st2workflowengine``. (bug fix) #4596
6675
* Update statsd metrics driver so any exception thrown by statsd library is treated as non fatal.

contrib/examples/actions/pythonactions/fibonacci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def fib(n):
2121
print(results)
2222
except Exception as e:
2323
traceback.print_exc(file=sys.stderr)
24-
sys.exit(str(e))
24+
sys.exit(six.text_type(e))

contrib/examples/actions/pythonactions/forloop_parse_github_repos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def run(self, content):
1616
repo_url = "https://github.com" + repo_half_url
1717
output[repo_name] = repo_url
1818
except Exception as e:
19-
raise Exception("Could not parse data: {}".format(str(e)))
19+
raise Exception("Could not parse data: {}".format(six.text_type(e)))
2020

2121
return (True, output)

contrib/examples/actions/pythonactions/forloop_push_github_repos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def run(self, data_to_push):
99
# Push data to a service here
1010
print(str(each_item))
1111
except Exception as e:
12-
raise Exception("Process failed: {}".format(str(e)))
12+
raise Exception("Process failed: {}".format(six.text_type(e)))
1313

1414
return (True, "Data pushed successfully")

contrib/examples/actions/ubuntu_pkg_info/ubuntu_pkg_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def main(args):
1414
try:
1515
payload = transformer.to_json(command_stdout, command_stderr, command_exitcode)
1616
except Exception as e:
17-
sys.stderr.write('JSON conversion failed. %s' % str(e))
17+
sys.stderr.write('JSON conversion failed. %s' % six.text_type(e))
1818
sys.exit(1)
1919

2020
sys.stdout.write(payload)

contrib/linux/actions/wait_for_ssh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import time
44

5+
import six
56
from oslo_config import cfg
67

78
from st2common.runners.base_action import Action
@@ -31,7 +32,7 @@ def run(self, hostname, port, username, password=None, keyfile=None, ssh_timeout
3132
return True
3233
except Exception as e:
3334
self.logger.info('Attempt %s failed (%s), sleeping for %s seconds...' %
34-
(attempt, str(e), sleep_delay))
35+
(attempt, six.text_type(e), sleep_delay))
3536
time.sleep(sleep_delay)
3637

3738
raise Exception('Exceeded max retries (%s)' % (retries))

contrib/packs/actions/pack_mgmt/get_installed.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import os
1717
import yaml
1818

19+
import six
20+
1921
from git.repo import Repo
2022
from git.exc import InvalidGitRepositoryError
2123

@@ -57,7 +59,8 @@ def run(self, pack):
5759
try:
5860
details = self._parse_yaml_file(metadata_file)
5961
except Exception as e:
60-
error = ('Pack "%s" doesn\'t contain a valid pack.yaml file: %s' % (pack, str(e)))
62+
error = ('Pack "%s" doesn\'t contain a valid pack.yaml file: %s' % (pack,
63+
six.text_type(e)))
6164
raise Exception(error)
6265

6366
try:

contrib/runners/action_chain_runner/action_chain_runner/action_chain_runner.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
# limitations under the License.
1515

1616
from __future__ import absolute_import
17+
1718
import eventlet
1819
import traceback
1920
import uuid
2021
import datetime
2122

23+
import six
2224
from jsonschema import exceptions as json_schema_exc
2325

2426
from st2common.runners.base import ActionRunner
@@ -259,7 +261,7 @@ def pre_run(self):
259261
expected_type=dict)
260262
except Exception as e:
261263
message = ('Failed to parse action chain definition from "%s": %s' %
262-
(chainspec_file, str(e)))
264+
(chainspec_file, six.text_type(e)))
263265
LOG.exception('Failed to load action chain definition.')
264266
raise runner_exc.ActionRunnerPreRunError(message)
265267

@@ -268,11 +270,11 @@ def pre_run(self):
268270
except json_schema_exc.ValidationError as e:
269271
# preserve the whole nasty jsonschema message as that is better to get to the
270272
# root cause
271-
message = str(e)
273+
message = six.text_type(e)
272274
LOG.exception('Failed to instantiate ActionChain.')
273275
raise runner_exc.ActionRunnerPreRunError(message)
274276
except Exception as e:
275-
message = str(e)
277+
message = six.text_type(e)
276278
LOG.exception('Failed to instantiate ActionChain.')
277279
raise runner_exc.ActionRunnerPreRunError(message)
278280

@@ -288,7 +290,7 @@ def pre_run(self):
288290
try:
289291
self.chain_holder.validate()
290292
except Exception as e:
291-
raise runner_exc.ActionRunnerPreRunError(str(e))
293+
raise runner_exc.ActionRunnerPreRunError(six.text_type(e))
292294

293295
def run(self, action_parameters):
294296
# Run the action chain.
@@ -610,7 +612,7 @@ def _run_chain(self, action_parameters, resuming=False):
610612

611613
def _format_error(self, e, msg):
612614
return {
613-
'error': '%s. %s' % (msg, str(e)),
615+
'error': '%s. %s' % (msg, six.text_type(e)),
614616
'traceback': traceback.format_exc(10)
615617
}
616618

@@ -657,7 +659,7 @@ def _render_publish_vars(action_node, action_parameters, execution_result,
657659
key = getattr(e, 'key', None)
658660
value = getattr(e, 'value', None)
659661
msg = ('Failed rendering value for publish parameter "%s" in task "%s" '
660-
'(template string=%s): %s' % (key, action_node.name, value, str(e)))
662+
'(template string=%s): %s' % (key, action_node.name, value, six.text_type(e)))
661663
raise action_exc.ParameterRenderingFailedException(msg)
662664

663665
return rendered_result
@@ -699,7 +701,7 @@ def _resolve_params(action_node, original_parameters, results, chain_vars, chain
699701
key = getattr(e, 'key', None)
700702
value = getattr(e, 'value', None)
701703
msg = ('Failed rendering value for action parameter "%s" in task "%s" '
702-
'(template string=%s): %s') % (key, action_node.name, value, str(e))
704+
'(template string=%s): %s') % (key, action_node.name, value, six.text_type(e))
703705
raise action_exc.ParameterRenderingFailedException(msg)
704706
LOG.debug('Rendered params: %s: Type: %s', rendered_params, type(rendered_params))
705707
return rendered_params

contrib/runners/action_chain_runner/dist_utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@
1515
# limitations under the License.
1616

1717
from __future__ import absolute_import
18+
1819
import os
1920
import re
2021
import sys
2122

2223
from distutils.version import StrictVersion
2324

25+
# NOTE: This script can't rely on any 3rd party dependency so we need to use this code here
26+
PY3 = sys.version_info[0] == 3
27+
28+
if PY3:
29+
text_type = str
30+
else:
31+
text_type = unicode
32+
2433
GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'
2534

2635
try:
2736
import pip
2837
from pip import __version__ as pip_version
2938
except ImportError as e:
30-
print('Failed to import pip: %s' % (str(e)))
39+
print('Failed to import pip: %s' % (text_type(e)))
3140
print('')
3241
print('Download pip:\n%s' % (GET_PIP))
3342
sys.exit(1)
@@ -41,7 +50,7 @@
4150
try:
4251
from pip._internal.req.req_file import parse_requirements
4352
except ImportError as e:
44-
print('Failed to import parse_requirements from pip: %s' % (str(e)))
53+
print('Failed to import parse_requirements from pip: %s' % (text_type(e)))
4554
print('Using pip: %s' % (str(pip_version)))
4655
sys.exit(1)
4756

contrib/runners/action_chain_runner/tests/unit/test_actionchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def test_chain_runner_publish_param_rendering_failure(self, request):
687687
# rendering failure
688688
expected_error = ('Failed rendering value for publish parameter "p1" in '
689689
'task "c2" (template string={{ not_defined }}):')
690-
self.assertTrue(expected_error in str(e))
690+
self.assertTrue(expected_error in six.text_type(e))
691691
pass
692692
else:
693693
self.fail('Exception was not thrown')

0 commit comments

Comments
 (0)