Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Better example code?

Đang mở
#53 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@ericzbeard đang làm issue này rồi.

Từ ngày 13/10/2022.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
Python
Star
107
Fork
46
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws-cloudformation/cloudformation-cli-python-plugin

Tất cả issue của aws-cloudformation/cloudformation-cli-python-plugin

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.