Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Better example code?

Offen
#53 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@ericzbeard arbeitet bereits daran.

Seit 13.10.2022.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

documentation good first issue p1

This could also be misunderstanding, the current example code in the create_handler looks like:

    try:
        if isinstance(session, SessionProxy):
            client = session.client("s3")
        # Setting Status to success will signal to cfn that the operation is complete
        progress.status = OperationStatus.SUCCESS
    except TypeError as e:
        # exceptions module lets CloudFormation know the type of failure that occurred
        raise exceptions.InternalFailure(f"was not expecting type {e}")
        # this can also be done by returning a failed progress event
        # return ProgressEvent.failed(HandlerErrorCode.InternalFailure, f"was not expecting type {e}")
    return progress

as far as I can see that will never raise a TypeError. So I feel this code will be better to get people started:

    if not isinstance(session, SessionProxy):
        # exceptions module lets CloudFormation know the type of failure that occurred
        raise exceptions.InternalFailure(f"session should be a SessionProxy")
        # this can also be done by returning a failed progress event
        # return ProgressEvent.failed(HandlerErrorCode.InternalFailure, f"was not expecting type {e}")
    
    # TODO: put code here

    # Setting Status to success will signal to cfn that the operation is complete
    progress.status = OperationStatus.SUCCESS
    return progress

That shows the same concepts, without having that try except increasing indentation.

Even if it would throw that exception, I don't see the added value of replacing that with a custom exception (it makes debugging harder if we do not re-raise the original exception)

If CloudFormation requires the thrown exception to be from the exceptions, this sort of code will lead to pokemon exception handling (gotta catch them all), and converting unknown exceptions to InternlFailure would be better handled in cloudformation-cli-python-lib

Vorherrschende Sprache
Python
Sterne
107
Forks
46
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aws-cloudformation/cloudformation-cli-python-plugin

Alle Issues in aws-cloudformation/cloudformation-cli-python-plugin

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.