Skip to content
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-ErrorMessages-78207.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "Error Messages",
"description": "Standardize CLI error message format to use `aws: [ERROR]: <message>` prefix for consistency across all error types."
}
3 changes: 2 additions & 1 deletion awscli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import copy
import sys
from difflib import get_close_matches
from awscli.errorformat import format_error_message

HELP_BLURB = (
"To see help text, you can run:\n"
Expand Down Expand Up @@ -113,7 +114,7 @@ def error(self, message):
should raise an exception.
"""
usage_message = self.format_usage()
error_message = f'{self.prog}: [ERROR]: {message}'
error_message = format_error_message(message, prog=self.prog)
raise ArgParseException(f'{error_message}\n\n{usage_message}')


Expand Down
9 changes: 5 additions & 4 deletions awscli/customizations/configure/mfalogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from awscli.customizations.commands import BasicCommand
from awscli.customizations.configure import profile_to_section
from awscli.customizations.configure.writer import ConfigFileWriter
from awscli.errorformat import write_error

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,7 +143,7 @@ def _get_mfa_token(self):
'None', 'mfa_token', 'MFA token code'
)
if not token_code:
sys.stderr.write("MFA token code is required\n")
write_error(sys.stderr, "MFA token code is required")
return None
return token_code

Expand All @@ -156,7 +157,7 @@ def _call_sts_get_session_token(self, sts_client, duration_seconds, mfa_serial,
)
return response
except ClientError as e:
sys.stderr.write(f"An error occurred: {e}\n")
write_error(sys.stderr, f"An error occurred: {e}")
return None

def _resolve_mfa_serial(self, parsed_args, source_config):
Expand All @@ -167,7 +168,7 @@ def _resolve_mfa_serial(self, parsed_args, source_config):
'None', 'mfa_serial', 'MFA serial number or ARN'
)
if not mfa_serial:
sys.stderr.write("MFA serial number or MFA device ARN is required\n")
write_error(sys.stderr, "MFA serial number or MFA device ARN is required")
return None
return mfa_serial

Expand Down Expand Up @@ -252,7 +253,7 @@ def _handle_interactive_prompting(self, parsed_args, duration_seconds):
'None', config_name, prompt_text
)
if not value or value == 'None':
sys.stderr.write(f"{prompt_text} is required\n")
write_error(sys.stderr, f"{prompt_text} is required")
return 1
values[config_name] = value

Expand Down
10 changes: 5 additions & 5 deletions awscli/customizations/ecs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ def __init__(self, **kwargs):


class MissingPropertyError(ECSError):
fmt = "Error: Resource '{resource}' must include property '{prop_name}'"
fmt = "Resource '{resource}' must include property '{prop_name}'"


class FileLoadError(ECSError):
fmt = "Error: Unable to load file at {file_path}: {error}"
fmt = "Unable to load file at {file_path}: {error}"


class InvalidPlatformError(ECSError):
fmt = "Error: {resource} '{name}' must support 'ECS' compute platform"
fmt = "{resource} '{name}' must support 'ECS' compute platform"


class InvalidProperyError(ECSError):
fmt = (
"Error: deployment group '{dg_name}' does not target "
"deployment group '{dg_name}' does not target "
"ECS {resource} '{resource_name}'"
)


class InvalidServiceError(ECSError):
fmt = "Error: Service '{service}' not found in cluster '{cluster}'"
fmt = "Service '{service}' not found in cluster '{cluster}'"


class ServiceClientError(ECSError):
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/emr/applicationutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def build_applications(region, parsed_applications, ami_version=None):
)
else:
raise ParamValidationError(
'aws: error: AMI version %s is not '
'AMI version %s is not '
'compatible with HBase.' % ami_version
)
elif app_name == constants.IMPALA:
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/emr/createcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _run_main_command(self, parsed_args, parsed_globals):
)
except ValueError:
raise ParamValidationError(
'aws: error: invalid json argument for '
'invalid json argument for '
'option --configurations'
)

Expand Down Expand Up @@ -697,7 +697,7 @@ def _build_bootstrap_actions(self, cluster, parsed_boostrap_actions):
> constants.MAX_BOOTSTRAP_ACTION_NUMBER
):
raise ParamValidationError(
'aws: error: maximum number of '
'maximum number of '
'bootstrap actions for a cluster exceeded.'
)

Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/emr/emrutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def apply_boolean_options(
):
if true_option and false_option:
error_message = (
'aws: error: cannot use both '
'cannot use both '
+ true_option_name
+ ' and '
+ false_option_name
Expand Down
46 changes: 23 additions & 23 deletions awscli/customizations/emr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MissingParametersError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: The following required parameters are missing for '
'The following required parameters are missing for '
'{object_name}: {missing}.'
)

Expand All @@ -53,7 +53,7 @@ class EmptyListError(EmrError, ParamValidationError):
:ivar param: The provided list parameter
"""

fmt = 'aws: error: The prameter {param} cannot be an empty list.'
fmt = 'The prameter {param} cannot be an empty list.'


class MissingRequiredInstanceGroupsError(EmrError, ParamValidationError):
Expand All @@ -63,7 +63,7 @@ class MissingRequiredInstanceGroupsError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: Must specify either --instance-groups or '
'Must specify either --instance-groups or '
'--instance-type with --instance-count(optional) to '
'configure instance groups.'
)
Expand All @@ -77,7 +77,7 @@ class InstanceGroupsValidationError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: You may not specify --instance-type '
'You may not specify --instance-type '
'or --instance-count with --instance-groups, '
'because --instance-type and --instance-count are '
'shortcut options for --instance-groups.'
Expand All @@ -91,7 +91,7 @@ class InvalidAmiVersionError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: The supplied AMI version "{ami_version}" is invalid.'
'The supplied AMI version "{ami_version}" is invalid.'
' Please see AMI Versions Supported in Amazon EMR in '
'Amazon Elastic MapReduce Developer Guide: '
'http://docs.aws.amazon.com/ElasticMapReduce/'
Expand All @@ -108,7 +108,7 @@ class MissingBooleanOptionsError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: Must specify one of the following boolean options: '
'Must specify one of the following boolean options: '
'{true_option}|{false_option}.'
)

Expand All @@ -120,7 +120,7 @@ class UnknownStepTypeError(EmrError, ParamValidationError):
:ivar step_type: the step_type provided.
"""

fmt = 'aws: error: The step type {step_type} is not supported.'
fmt = 'The step type {step_type} is not supported.'


class UnknownIamEndpointError(EmrError):
Expand Down Expand Up @@ -154,7 +154,7 @@ class LogUriError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: LogUri not specified. You must specify a logUri '
'LogUri not specified. You must specify a logUri '
'if you enable debugging when creating a cluster.'
)

Expand Down Expand Up @@ -212,7 +212,7 @@ class SubnetAndAzValidationError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: You may not specify both a SubnetId and an Availabili'
'You may not specify both a SubnetId and an Availabili'
'tyZone (placement) because ec2SubnetId implies a placement.'
)

Expand All @@ -222,7 +222,7 @@ class RequiredOptionsError(EmrError, ParamValidationError):
Either of option1 or option2 is required.
"""

fmt = 'aws: error: Either {option1} or {option2} is required.'
fmt = 'Either {option1} or {option2} is required.'


class MutualExclusiveOptionError(EmrError, ParamValidationError):
Expand All @@ -236,7 +236,7 @@ class MutualExclusiveOptionError(EmrError, ParamValidationError):

def __init__(self, **kwargs):
msg = (
'aws: error: You cannot specify both '
'You cannot specify both '
+ kwargs.get('option1', '')
+ ' and '
+ kwargs.get('option2', '')
Expand All @@ -256,7 +256,7 @@ class MissingApplicationsError(EmrError, ParamValidationError):

def __init__(self, **kwargs):
msg = (
'aws: error: Some of the steps require the following'
'Some of the steps require the following'
' applications to be installed: '
+ ', '.join(kwargs['applications'])
+ '. Please install the'
Expand All @@ -270,7 +270,7 @@ class ClusterTerminatedError(EmrError):
The cluster is terminating or has already terminated.
"""

fmt = 'aws: error: Cluster terminating or already terminated.'
fmt = 'Cluster terminating or already terminated.'


class ClusterStatesFilterValidationError(EmrError, ParamValidationError):
Expand All @@ -282,7 +282,7 @@ class ClusterStatesFilterValidationError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: You can specify only one of the cluster state '
'You can specify only one of the cluster state '
'filters: --cluster-states, --active, --terminated, --failed.'
)

Expand All @@ -296,7 +296,7 @@ class MissingClusterAttributesError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: Must specify one of the following boolean options: '
'Must specify one of the following boolean options: '
'--visible-to-all-users|--no-visible-to-all-users, '
'--termination-protected|--no-termination-protected, '
'--auto-terminate|--no-auto-terminate, '
Expand All @@ -314,14 +314,14 @@ class InvalidEmrFsArgumentsError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: {parent_object_name} is not specified. Thus, '
'{parent_object_name} is not specified. Thus, '
' following parameters are invalid: {invalid}'
)


class DuplicateEmrFsConfigurationError(EmrError, ParamValidationError):
fmt = (
'aws: error: EMRFS should be configured either using '
'EMRFS should be configured either using '
'--configuration or --emrfs but not both'
)

Expand All @@ -334,7 +334,7 @@ class UnknownCseProviderTypeError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: The client side encryption type "{provider_type}" is '
'The client side encryption type "{provider_type}" is '
'not supported. You must specify either KMS or Custom'
)

Expand All @@ -347,7 +347,7 @@ class UnknownEncryptionTypeError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: The encryption type "{encryption}" is invalid. '
'The encryption type "{encryption}" is invalid. '
'You must specify either ServerSide or ClientSide'
)

Expand All @@ -361,14 +361,14 @@ class BothSseAndEncryptionConfiguredError(EmrError, ParamValidationError):
"""

fmt = (
'aws: error: Both SSE={sse} and Encryption={encryption} are '
'Both SSE={sse} and Encryption={encryption} are '
'configured for --emrfs. You must specify only one of the two.'
)


class InvalidBooleanConfigError(EmrError, ParamValidationError):
fmt = (
"aws: error: {config_value} for {config_key} in the config file is "
"{config_value} for {config_key} in the config file is "
"invalid. The value should be either 'True' or 'False'. Use "
"'aws configure set {profile_var_name}.emr.{config_key} <value>' "
"command to set a valid value."
Expand All @@ -377,13 +377,13 @@ class InvalidBooleanConfigError(EmrError, ParamValidationError):

class UnsupportedCommandWithReleaseError(EmrError, ParamValidationError):
fmt = (
"aws: error: {command} is not supported with "
"{command} is not supported with "
"'{release_label}' release."
)


class MissingAutoScalingRoleError(EmrError, ParamValidationError):
fmt = (
"aws: error: Must specify --auto-scaling-role when configuring an "
"Must specify --auto-scaling-role when configuring an "
"AutoScaling policy for an instance group."
)
4 changes: 2 additions & 2 deletions awscli/customizations/emr/hbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _check_type(self, type):
type = type.lower()
if type != constants.FULL and type != constants.INCREMENTAL:
raise ParamValidationError(
'aws: error: invalid type. '
'invalid type. '
'type should be either '
+ constants.FULL
+ ' or '
Expand All @@ -145,7 +145,7 @@ def _check_unit(self, unit):
and unit != constants.DAYS
):
raise ParamValidationError(
'aws: error: invalid unit. unit should be one of'
'invalid unit. unit should be one of'
' the following values: '
+ constants.MINUTES
+ ', '
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/emr/installapplications.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def _check_for_supported_apps(self, parsed_applications):
if app_name in constants.APPLICATIONS:
if app_name not in self.supported_apps:
raise ParamValidationError(
"aws: error: " + app_config['Name'] + " cannot be"
app_config['Name'] + " cannot be"
" installed on a running cluster. 'Name' should be one"
" of the following: " + ', '.join(self.supported_apps)
)
else:
raise ParamValidationError(
"aws: error: Unknown application: "
"Unknown application: "
+ app_config['Name']
+ ". 'Name' should be one of the following: "
+ ', '.join(constants.APPLICATIONS)
Expand Down
Loading