Skip to content

Commit 1824610

Browse files
authored
Fix local mode error message handling (#272)
1 parent 7c2073c commit 1824610

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66
========
77

88
* bug-fix: Session: include role path in ``get_execution_role()`` result
9+
* bug-fix: Local Mode: fix RuntimeError handling
910

1011
1.5.2
1112
=====

src/sagemaker/local/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def train(self, input_data_config, hyperparameters):
112112
except RuntimeError as e:
113113
# _stream_output() doesn't have the command line. We will handle the exception
114114
# which contains the exit code and append the command line to it.
115-
msg = "Failed to run: %s, %s" % (compose_command, e.message)
115+
msg = "Failed to run: %s, %s" % (compose_command, str(e))
116116
raise RuntimeError(msg)
117117

118118
s3_artifacts = self.retrieve_artifacts(compose_data)
@@ -516,7 +516,7 @@ def run(self):
516516
except RuntimeError as e:
517517
# _stream_output() doesn't have the command line. We will handle the exception
518518
# which contains the exit code and append the command line to it.
519-
msg = "Failed to run: %s, %s" % (self.command, e.message)
519+
msg = "Failed to run: %s, %s" % (self.command, str(e))
520520
raise RuntimeError(msg)
521521

522522
def down(self):

tests/unit/test_image.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ def test_train(_download_folder, _cleanup, popen, _stream_output, LocalSession,
246246
assert config['services'][h]['command'] == 'train'
247247

248248

249+
@patch('sagemaker.local.local_session.LocalSession')
250+
@patch('sagemaker.local.image._stream_output', side_effect=RuntimeError('this is expected'))
251+
@patch('subprocess.Popen')
252+
@patch('sagemaker.local.image._SageMakerContainer._cleanup')
253+
@patch('sagemaker.local.image._SageMakerContainer._download_folder')
254+
def test_train_error(_download_folder, _cleanup, popen, _stream_output, LocalSession, tmpdir, sagemaker_session):
255+
directories = [str(tmpdir.mkdir('container-root')), str(tmpdir.mkdir('data'))]
256+
257+
with patch('sagemaker.local.image._SageMakerContainer._create_tmp_folder', side_effect=directories):
258+
instance_count = 2
259+
image = 'my-image'
260+
sagemaker_container = _SageMakerContainer('local', instance_count, image, sagemaker_session=sagemaker_session)
261+
262+
with pytest.raises(RuntimeError) as e:
263+
sagemaker_container.train(INPUT_DATA_CONFIG, HYPERPARAMETERS)
264+
265+
assert 'this is expected' in str(e)
266+
267+
249268
@patch('sagemaker.local.local_session.LocalSession')
250269
@patch('sagemaker.local.image._stream_output')
251270
@patch('subprocess.Popen')

0 commit comments

Comments
 (0)