aws/aws-sam-cli

Bug: sam validate - UnexpectedRuleException

thedarkknight197 opened this issue · 5 comments

Description:

sam validate --lint issue on fedora:

 sam validate --lint

Error: Tried to append rules but got an error: cannot import name 'REGISTRY_SCHEMAS' from 'cfnlint.helpers' (/usr/local/aws-sam-cli/1.123.0/dist/_internal/cfnlint/helpers.pyc)
Traceback:
  File "click/core.py", line 1078, in main
  File "click/core.py", line 1688, in invoke
  File "click/core.py", line 1434, in invoke
  File "click/core.py", line 783, in invoke
  File "samcli/cli/cli_config_file.py", line 347, in wrapper
  File "click/decorators.py", line 92, in new_func
  File "click/core.py", line 783, in invoke
  File "samcli/lib/telemetry/metric.py", line 185, in wrapped
  File "samcli/lib/telemetry/metric.py", line 150, in wrapped
  File "samcli/lib/utils/version_checker.py", line 43, in wrapped
  File "samcli/cli/main.py", line 95, in wrapper
  File "samcli/commands/_utils/cdk_support_decorators.py", line 40, in wrapped
  File "samcli/commands/_utils/command_exception_handler.py", line 89, in wrapper_command_exception_handler
  File "samcli/commands/_utils/command_exception_handler.py", line 69, in wrapper_command_exception_handler
  File "samcli/commands/validate/validate.py", line 70, in cli
  File "samcli/commands/validate/validate.py", line 87, in do_cli
  File "samcli/commands/validate/validate.py", line 176, in _lint
  File "cfnlint/api.py", line 62, in lint
    runner = Runner(config_mixin)
             ^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/runner.py", line 228, in __init__
    self._get_rules()
  File "cfnlint/runner.py", line 255, in _get_rules
    raise UnexpectedRuleException(

An unexpected error was encountered while executing "sam validate".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20validate%20-%20UnexpectedRuleException
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20validate%20-%20UnexpectedRuleException

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Fedora Linux 40 (Workstation Edition) Linux 6.9.10-200.fc40.x86_64 Firmware 1.C0
  2. sam --version: 1.123.0
 sam --info
{
  "version": "1.123.0",
  "system": {
    "python": "3.11.8",
    "os": "Linux-6.9.10-200.fc40.x86_64-x86_64-with-glibc2.39"
  },
  "additional_dependencies": {
    "docker_engine": "27.1.1",
    "aws_cdk": "Not available",
    "terraform": "1.9.2"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Debug result:

2024-08-28 21:40:49 Looking for CFLINTRC before attempting to load
2024-08-28 21:40:49 Validating User CFNLINTRC
2024-08-28 21:40:49 Validating CFNLINTRC config with given JSONSchema
2024-08-28 21:40:49 Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/main/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'CFNLINTRC configuration schema', 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'additionalProperties': False, 'description': 'Configure rules', 'patternProperties': {'^.*$': {'patternProperties': {'^.*$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}, {'items': {'type': 'string'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'boolean'}]}}, 'type': 'object'}}, 'type': 'object'}, 'custom_rules': {'description': 'custom rule file to use', 'type': 'string'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'merge_configs': {'description': 'Merges lists between configuration layers', 'type': 'boolean'}, 'output_file': {'description': 'Path to the file to write the main output to', 'type': 'string'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'registry_schemas': {'description': 'One or more directories of CloudFormation Registry Resource Schemas', 'items': {'type': 'string'}, 'type': 'array'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}}, 'title': 'CFNLINTRC JSON Schema', 'type': 'object'}
2024-08-28 21:40:49 Config used: {}
2024-08-28 21:40:49 CFNLINTRC looks valid!
2024-08-28 21:40:49 Validating Project CFNLINTRC
2024-08-28 21:40:49 Validating CFNLINTRC config with given JSONSchema
2024-08-28 21:40:49 Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/main/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'description': 'CFNLINTRC configuration schema', 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'additionalProperties': False, 'description': 'Configure rules', 'patternProperties': {'^.*$': {'patternProperties': {'^.*$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}, {'items': {'type': 'string'}, 'type': 'array'}, {'items': {'type': 'integer'}, 'type': 'array'}, {'items': {'type': 'string'}, 'type': 'boolean'}]}}, 'type': 'object'}}, 'type': 'object'}, 'custom_rules': {'description': 'custom rule file to use', 'type': 'string'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'merge_configs': {'description': 'Merges lists between configuration layers', 'type': 'boolean'}, 'output_file': {'description': 'Path to the file to write the main output to', 'type': 'string'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'registry_schemas': {'description': 'One or more directories of CloudFormation Registry Resource Schemas', 'items': {'type': 'string'}, 'type': 'array'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}}, 'title': 'CFNLINTRC JSON Schema', 'type': 'object'}
2024-08-28 21:40:49 Config used: {}
2024-08-28 21:40:49 CFNLINTRC looks valid!
2024-08-28 21:40:49 User configuration loaded as
2024-08-28 21:40:49 {}
2024-08-28 21:40:49 Project configuration loaded as
2024-08-28 21:40:49 {}
2024-08-28 21:40:49 Merging configurations...
2024-08-28 21:40:49,695 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                                                                                                                                                
2024-08-28 21:40:49,701 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                                                                                                                                                
2024-08-28 21:40:49,701 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'c6a17318-1130-480b-8f6e-3024524cdac3', 'installationId': 'ffb7f4fe-4456-4c8c-8202-963a7cc5ac78', 'sessionId': 'a799ef77-0aab-47b8-beb1-6ad3e645dd93', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8',    
'samcliVersion': '1.123.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam validate', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '43ebdb97fdcdc622b586a17bf390148007084a9fe4df36f813174e98bb5f779b', 'initialCommit': None},   
'duration': 437, 'exitReason': 'UnexpectedRuleException', 'exitCode': 255}}]}                                                                                                                                                                                                                                       
2024-08-28 21:40:49,701 | Unable to find Click Context for getting session_id.                                                                                                                                                                                                                                      
2024-08-28 21:40:49,703 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'fa967829-64b3-4c86-a9fc-702d35810845', 'installationId': 'ffb7f4fe-4456-4c8c-8202-963a7cc5ac78', 'sessionId': 'a799ef77-0aab-47b8-beb1-6ad3e645dd93', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8',        
'samcliVersion': '1.123.0', 'commandName': 'sam validate', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '5c1e048d8a1547ce9a03138c44150c20', 'time_stamp': '2024-08-28 19:40:49.108', 'exception_name': None}, {'event_name':               
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '6bbbe06b47af4ac892cd48b38fe80e2f', 'time_stamp': '2024-08-28 19:40:49.257', 'exception_name': None}, {'event_name': 'UsedFeature', 'event_value': 'CFNLint', 'thread_id': '8b406a1acd9040c5a482c3814c386742', 'time_stamp': '2024-08-28             
19:40:49.641', 'exception_name': None}]}}}]}                                                                                                                                                                                                                                                                        
2024-08-28 21:40:50,234 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)                                                                                                                                                          
2024-08-28 21:40:50,237 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)                                                                                                                                                          

Error: Tried to append rules but got an error: cannot import name 'REGISTRY_SCHEMAS' from 'cfnlint.helpers' (/usr/local/aws-sam-cli/1.123.0/dist/_internal/cfnlint/helpers.pyc)
Traceback:
  File "click/core.py", line 1078, in main
  File "click/core.py", line 1688, in invoke
  File "click/core.py", line 1434, in invoke
  File "click/core.py", line 783, in invoke
  File "samcli/cli/cli_config_file.py", line 347, in wrapper
  File "click/decorators.py", line 92, in new_func
  File "click/core.py", line 783, in invoke
  File "samcli/lib/telemetry/metric.py", line 185, in wrapped
  File "samcli/lib/telemetry/metric.py", line 150, in wrapped
  File "samcli/lib/utils/version_checker.py", line 43, in wrapped
  File "samcli/cli/main.py", line 95, in wrapper
  File "samcli/commands/_utils/cdk_support_decorators.py", line 40, in wrapped
  File "samcli/commands/_utils/command_exception_handler.py", line 89, in wrapper_command_exception_handler
  File "samcli/commands/_utils/command_exception_handler.py", line 69, in wrapper_command_exception_handler
  File "samcli/commands/validate/validate.py", line 70, in cli
  File "samcli/commands/validate/validate.py", line 87, in do_cli
  File "samcli/commands/validate/validate.py", line 176, in _lint
  File "cfnlint/api.py", line 62, in lint
    runner = Runner(config_mixin)
             ^^^^^^^^^^^^^^^^^^^^
  File "cfnlint/runner.py", line 228, in __init__
    self._get_rules()
  File "cfnlint/runner.py", line 255, in _get_rules
    raise UnexpectedRuleException(

An unexpected error was encountered while executing "sam validate".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20validate%20-%20UnexpectedRuleException
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20validate%20-%20UnexpectedRuleException

Thanks for reporting this I'm not able to reproduce this with a sample node20 project generated with sam init. Can you provide a sample project that we can use to reproduce this, or a set of steps to reproduce?

Bumped into the same issue after upgrading from v1.121 to v1.123.
What fixed it for me was to do a clean install of the cli.

sudo rm -rf /usr/local/aws-sam-cli/

note: replace with where you've installed your cli and be careful of rm -rf

thanks @fliodhais let me try

@fliodhais it solved, thanks

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.