Skip to content

ComponentBuilder.make_for_file() raises FileExistsError instead of FileNotFoundError when file does not exist #1076

Done

Description

@trackoor

ComponentBuilder.make_for_file() raises FileExistsError instead of FileNotFoundError when the supplied file path does not exist, so callers catching FileNotFoundError for a missing file get an uncaught FileExistsError.

Environment:

  • cyclonedx-python-lib: 11.12.0 (v11.12.0) and main (3d62bf6723)
  • OS / Python: Linux, Python 3

Steps to reproduce:

  1. Install cyclonedx-python-lib 11.12.0.
  2. With /tmp/requests-2.32.3-py3-none-any.whl absent, run:
python3 -c "from cyclonedx.contrib.component.builders import ComponentBuilder
try:
    ComponentBuilder().make_for_file('/tmp/requests-2.32.3-py3-none-any.whl', name='requests-2.32.3-py3-none-any.whl')
except Exception as exc:
    print(repr(exc))"

Actual output:

FileExistsError("Supplied file path '/tmp/requests-2.32.3-py3-none-any.whl' does not exist")

Expected output: FileNotFoundError("Supplied file path '/tmp/requests-2.32.3-py3-none-any.whl' does not exist"), matching Python's standard missing-file exception and open() in _file_sha1sum().

In cyclonedx/contrib/component/builders.py lines 48-49, if not exists(absolute_file_path): raises FileExistsError instead of FileNotFoundError.

Credit: https://ucsbplse.github.io/

Activity

  1. added
    bug
    good first issue
    help wanted
    contrib
    on Nov 25, 2026
  2. jkowalleck commented on Nov 25, 2026

    @jkowalleck
    Member

    caused by

    raise FileExistsError(f'Supplied file path {absolute_file_path!r} does not exist')

    a fix would not be a breaking change, as it is in the "contrib" area of the library.

    this one is ready to be worked on.

    CycloneDX Python library is a community effort - feel free to contribute to fix.

  3. changed the title [-]ComponentBuilder.make_for_file() raises FileExistsError instead of FileNotFoundError when file does not exist[/-] [+]`ComponentBuilder.make_for_file()` raises `FileExistsError` instead of `FileNotFoundError` when file does not exist[/+] on Nov 26, 2026
  4. jkowalleck commented on Nov 30, 2026

    @jkowalleck
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcontribgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions