Skip to content

Improve NoRegionError message with guidance on setting a region#3731

Open
viveka76 wants to merge 2 commits into
boto:developfrom
viveka76:improve-noregionerror-message
Open

Improve NoRegionError message with guidance on setting a region#3731
viveka76 wants to merge 2 commits into
boto:developfrom
viveka76:improve-noregionerror-message

Conversation

@viveka76

Copy link
Copy Markdown

Description of changes: Expands the NoRegionError message to tell users
how to set a region (region_name argument, AWS_DEFAULT_REGION, or
~/.aws/config), and calls out the common mistake of putting region in
~/.aws/credentials.
Message text only — no change to resolution behavior, precedence, or the
exception type. Backwards compatible. Unit test and changelog entry included.
By submitting this pull request, I confirm that you can use, modify, copy,
and redistribute this contribution, under the terms of your choice.

@SamRemis

Copy link
Copy Markdown
Contributor

@viveka76 , thank you for the PR! I agree, this error message could be more helpful.

There are a few notes before we can merge:

  1. The AWS CLI v1 catches this exception and expands on it, so this would wind up with a confusing error message for CLIv1 users where we mention the SDK specific error message. The CLIv1 is scheduled to go into maintenance mode on July 15th of this year, so they will no longer receive these updates at that point. Waiting until this date to merge would probably be the easiest way to handle this.
  2. The error message is good, but there are a few edits I'd like to make. I'll suggest a change with those shortly.
  3. The updated test doesn't define ctx but references it, so it will fail when it runs. Since error messages like this one are intended to be helpful and user-facing as opposed to part of the API contract that can be coded against, we generally don't assert on the content of the message directly. I'd recommend just reverting the changes to the test file.
  4. The PR description appears to be generated using an LLM. Please see our CONTRIBUTING.md file for guidance on how to use tools to contribute to this repo. Please update the PR description to include the info outlined there.

Comment on lines +215 to +217
message = str(ctx.exception)
self.assertIn('You must specify a region', message)
self.assertIn('AWS_DEFAULT_REGION', message)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
message = str(ctx.exception)
self.assertIn('You must specify a region', message)
self.assertIn('AWS_DEFAULT_REGION', message)

Comment thread botocore/exceptions.py
Comment on lines +247 to +250
'You must specify a region. Set it via the region_name argument '
'to the client/Session, the AWS_DEFAULT_REGION environment '
'variable, or "region" in ~/.aws/config (note: region goes in '
'~/.aws/config, not ~/.aws/credentials).'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
'You must specify a region. Set it via the region_name argument '
'to the client/Session, the AWS_DEFAULT_REGION environment '
'variable, or "region" in ~/.aws/config (note: region goes in '
'~/.aws/config, not ~/.aws/credentials).'
'You must specify a region. This can be done by passing the region_name '
'argument to the client or session, using the AWS_DEFAULT_REGION '
'environment variable, or setting "region" in the aws config file.'

The reasoning behind these suggested edits:

  • region can be set in the credentials file and it will be respected by botocore
  • the filepath for the config file is not hard-coded and can be specified using the AWS_CONFIG_FILE environment variable (same with AWS_SHARED_CREDENTIALS_FILE for the credentials file)
  • While we could still include a reference to the credentials file, that would be a lot of detail for an error message. Most of the common cases would be covered with this update.

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.

2 participants