Skip to content

Replaced generic ValueError with custom subclass when reporting unexpected resource status #855

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

Closed
wants to merge 3 commits into from

Conversation

arodiss
Copy link
Contributor

@arodiss arodiss commented Jun 14, 2019

Issue #, if available:
None

Description of changes:
Replaced generic ValueError with custom subclass when reporting unexpected resource status

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I used the commit message format described in CONTRIBUTING
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mvsusp
Copy link
Contributor

mvsusp commented Jun 14, 2019

Hello @arodiss, thanks for the contribution. Any special reasoning behinds creating a new special exception? I would tend to just use ValueError here otherwise.

@mvsusp mvsusp self-requested a review June 14, 2019 18:36
Copy link
Contributor

@mvsusp mvsusp left a comment

Choose a reason for hiding this comment

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

Hello @arodiss, thanks for the contribution. Any special reasoning behinds creating a new special exception? I would tend to just use ValueError here otherwise.

@arodiss
Copy link
Contributor Author

arodiss commented Jun 17, 2019

@mvsusp
I want to catch this specific situation in my client script, and to distinguish between "batch transformation status is failed because some records are malformed" and "ValueError was raised by one of the 10000 possible sources" I have to parse error message, which is meh.
Generally, I think that specific exception classes are strictly preferable over built-ins - they allow something for a client but do not demand anything from him.
Here my custom exception is inherited from the ValueError, so if somebody is not interested in specific handling - his code will work just as it did before

@mvsusp
Copy link
Contributor

mvsusp commented Jun 17, 2019

Agreed that is helpful in your use case. Thanks for your contribution!

@@ -0,0 +1,9 @@
from __future__ import absolute_import
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add copyright.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

message='Error creating model package {}: {} Reason: {}'.format(model_package_name, status, reason),
allowed_statuses=['Completed'],
actual_status=status
)
return desc

def create_endpoint_config(self, name, model_name, initial_instance_count, instance_type,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include unit tests, example

def test_create_endpoint_config(sagemaker_session):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

included

message='Error for {} {}: {} Reason: {}'.format(job_type, job, status, reason),
allowed_statuses=['Completed', 'Stopped'],
actual_status=status
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need unit tests here 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.

done

message='Error hosting endpoint {}: {} Reason: {}'.format(endpoint, status, reason),
allowed_statuses=['InService'],
actual_status=status
)
return desc
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -30,6 +30,7 @@
from sagemaker import vpc_utils
from sagemaker.user_agent import prepend_user_agent
from sagemaker.utils import name_from_image, secondary_training_status_changed, secondary_training_status_message
from sagemaker.exceptions import UnexpectedStatusException
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try to follow Google Python Style guide, http://google.github.io/styleguide/pyguide.html#224-decision

from sagemaker import exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.
I have to mention that other imports in the same file are quite far from the guide

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@arodiss
Copy link
Contributor Author

arodiss commented Jun 19, 2019

@mvsusp
All done.
Test failures are same as on the master

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jesterhazy
Copy link
Contributor

AWS CodeBuild CI Report

  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@arodiss
Copy link
Contributor Author

arodiss commented Jul 10, 2019

Moved to #919

@arodiss arodiss closed this Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants