Skip to content

Fix local mode error message #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG
========

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

1.5.2
=====
Expand Down
4 changes: 2 additions & 2 deletions src/sagemaker/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def train(self, input_data_config, hyperparameters):
except RuntimeError as e:
# _stream_output() doesn't have the command line. We will handle the exception
# which contains the exit code and append the command line to it.
msg = "Failed to run: %s, %s" % (compose_command, e.message)
msg = "Failed to run: %s, %s" % (compose_command, str(e))
raise RuntimeError(msg)

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

def down(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ def test_train(_download_folder, _cleanup, popen, _stream_output, LocalSession,
assert config['services'][h]['command'] == 'train'


@patch('sagemaker.local.local_session.LocalSession')
@patch('sagemaker.local.image._stream_output', side_effect=RuntimeError('this is expected'))
@patch('subprocess.Popen')
@patch('sagemaker.local.image._SageMakerContainer._cleanup')
@patch('sagemaker.local.image._SageMakerContainer._download_folder')
def test_train_error(_download_folder, _cleanup, popen, _stream_output, LocalSession, tmpdir, sagemaker_session):
directories = [str(tmpdir.mkdir('container-root')), str(tmpdir.mkdir('data'))]

with patch('sagemaker.local.image._SageMakerContainer._create_tmp_folder', side_effect=directories):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put it as a patch as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it relies on directories and I doubt putting that variable assignment directly in the patch annotation would fit in one line

instance_count = 2
image = 'my-image'
sagemaker_container = _SageMakerContainer('local', instance_count, image, sagemaker_session=sagemaker_session)

with pytest.raises(RuntimeError) as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this should be one single test. I would split it to be a serving_container_handles_failure or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure what you mean here. _stream_output is patched to return a RuntimeError, so all this is testing is that the eventual RuntimeError returned by train() contains the error message from the first RuntimeError

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm this is fine

sagemaker_container.train(INPUT_DATA_CONFIG, HYPERPARAMETERS)

assert 'this is expected' in str(e)


@patch('sagemaker.local.local_session.LocalSession')
@patch('sagemaker.local.image._stream_output')
@patch('subprocess.Popen')
Expand Down