Skip to content

cfn-lint as pre-commit hook fails with "--non-zero-exit-code": maximum recursion depth exceeded #4326

@folleymcklaukyn

Description

@folleymcklaukyn

CloudFormation Lint Version

v1.42.1

What operating system are you using?

Windows 11

Describe the bug

Summary:

cfn-lint fails in a pre-commit hook when using the flag --non-zero-exit-code, producing the error:
maximum recursion depth exceeded while calling a Python object

Environment

cfn-lint version: tested with v1.42.1 and v1.43.0
Python version: 3.11.9
pre-commit version: 4.5.0

  • NOTE: The issue can be reproduced using the information below. I created a new repository specifically to test and confirm the behavior, isolating cfn-lint from other hooks.

pre-commit configuration

repos:
  - repo: https://github.com/aws-cloudformation/cfn-lint
    rev: v1.42.1
    hooks:
      - id: cfn-lint-rc
        name: cfn-lint · Validate CloudFormation templates

.cfnlintrc.yaml

templates:
  - templates/**/*.yaml
non_zero_exit_code: error
# ignore_checks:
#   - W2001

Steps to reproduce

  1. Install and configure pre-commit in the repository
  2. Configure cfn-lint hook (code above) and copy .cfnlintrc.yaml to the root folder.
  3. Create a folder named templates and put the reproduction template there.
  4. In a terminal, run pre-commit run --all-files

Actual Behavior

$ pre-commit run --all-files
cfn-lint · Validate CloudFormation templates.............................Failed
- hook id: cfn-lint-rc
- exit code: 1

maximum recursion depth exceeded while calling a Python object

When non_zero_exit_code: error is omitted, the process works as intended:

$ pre-commit run --all-files
cfn-lint · Validate CloudFormation templates.............................Failed
- hook id: cfn-lint-rc
- exit code: 4

W2001 Parameter UnusedParameter not used.
templates\test_template.yaml:2:3

When ignore_checks is set, the process also works as intended.

  • NOTE: I currently don’t know how to execute cfn-lint in debug mode inside pre-commit, which is why I’m unable to include a debug log.

Expected behavior

$ pre-commit run --all-files
cfn-lint · Validate CloudFormation templates.............................Passed

Reproduction template

Parameters:
  UnusedParameter:
    Type: String
Resources:
  LogGroup:
    Type: AWS::Logs::LogGroup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions