Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve errors by hoisting ErrorInfo fields directly in error message #354

Merged
merged 20 commits into from
Feb 24, 2022

Conversation

alicejli
Copy link
Contributor

@alicejli alicejli commented Dec 3, 2021

As part of the overall GAPIC Error Details Improvements project, this feature improves the usability of the error information by including three additional fields (if available) directly in the error itself e.g. ErrorInfo that offer more detailed information for troubleshooting. These three fields are domain, reason, and metadata.

This PR also includes getters for those fields so users may access them directly.

This PR is dependent on googleapis/common-protos-php#27 being merged which will not happen until post-freeze, sometime in January.

Please ping me for internal docs if desired.

Current REST sample error:

PHP Fatal error:  Uncaught Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project <id> before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com\/google.rpc.Help",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id>"
                }
            ]
        },
        {
            "@type": "type.googleapis.com\/google.rpc.ErrorInfo",
            "reason": "SERVICE_DISABLED",
            "domain": "googleapis.com",
            "metadata": {
                "consumer": "projects\/<id>",
                "service": "translate.googleapis.com"
            }
        }
    ]
}

With this change, REST sample error:

Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project <id> before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "domain": "googleapis.com",
    "reason": "SERVICE_DISABLED",
    "errorInfoMetadata": {
        "consumer": "projects\/<id>",
        "service": "translate.googleapis.com"
    },
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com\/google.rpc.Help",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id>"
                }
            ]
        },
        {
            "@type": "type.googleapis.com\/google.rpc.ErrorInfo",
            "reason": "SERVICE_DISABLED",
            "domain": "googleapis.com",
            "metadata": {
                "consumer": "projects\/<id>",
                "service": "translate.googleapis.com"
            }
        }
    ]
}

Current GRPC sample error:

Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project <id> before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "google.rpc.errorinfo-bin",
            "data": "<Unknown Binary Data>"
            }
        },
        {
            "@type": "google.rpc.help-bin",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id>"
                }
            ]
        },
        {
            "@type": "grpc-status-details-bin",
            "data": "<Unknown Binary Data>"
        },
        {
            "@type": "grpc-server-stats-bin",
            "data": "<Unknown Binary Data>"
        }
    ]
}

With this change, GRPC sample error:

Google\ApiCore\ApiException: {
    "message": "Cloud Translation API has not been used in project <id> before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "domain": "googleapis.com",
    "reason": "SERVICE_DISABLED",
    "errorInfoMetadata": {
        "service": "translate.googleapis.com",
        "consumer": "projects\/<id>"
    },
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "google.rpc.errorinfo-bin",
            "reason": "SERVICE_DISABLED",
            "domain": "googleapis.com",
            "metadata": {
                "service": "translate.googleapis.com",
                "consumer": "projects\/<id>"
            }
        },
        {
            "@type": "google.rpc.help-bin",
            "links": [
                {
                    "description": "Google developers console API activation",
                    "url": "https:\/\/console.developers.google.com\/apis\/api\/translate.googleapis.com\/overview?project=<id>"
                }
            ]
        },
        {
            "@type": "grpc-status-details-bin",
            "data": "<Unknown Binary Data>"
        },
        {
            "@type": "grpc-server-stats-bin",
            "data": "<Unknown Binary Data>"
        }
    ]
}

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 3, 2021
@alicejli
Copy link
Contributor Author

alicejli commented Dec 7, 2021

Requesting @noahdietz , @bshaffer as PHP owners, and @summer-ji-eng as Error Improvement project lead for review.
Tests will fail until googleapis/common-protos-php#27 is merged.

This is a non urgent review as we will not be able to release this until post freeze. Thanks!

Copy link
Contributor

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments to start. Can you also run the php formatting tool? Should be in the readme somewhere.

src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
@noahdietz noahdietz self-requested a review January 18, 2022 22:14
@noahdietz noahdietz changed the title [DO NOT MERGE] feat: improve errors by hoisting ErrorInfo fields directly in error message feat: improve errors by hoisting ErrorInfo fields directly in error message Jan 18, 2022
@noahdietz noahdietz marked this pull request as ready for review January 18, 2022 22:16
@noahdietz noahdietz requested review from a team as code owners January 18, 2022 22:16
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
Copy link
Contributor

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add php doc comments to all of the added public APIs?

src/ApiException.php Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
Copy link

@summer-ji-eng summer-ji-eng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this implementation cover for REST mode?

src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
@alicejli
Copy link
Contributor Author

Does this implementation cover for REST mode?

Yup! I added a test for the error info in REST response. Good catch.

@alicejli alicejli closed this Feb 12, 2022
@alicejli alicejli reopened this Feb 12, 2022
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
Copy link
Contributor

@noahdietz noahdietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great stuff Alice. I will let @bshaffer review/Approve.

@summer-ji-eng
Copy link

Thanks Alice for your work. LGTM.
Not blocker, but please add the integration test for grpc and rest.

Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions for cleanup, otherwise looks great

src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
src/ApiException.php Outdated Show resolved Hide resolved
VERSION Outdated Show resolved Hide resolved
@alicejli alicejli merged commit 178da3d into googleapis:main Feb 24, 2022
@alicejli alicejli deleted the errorimprovement branch February 24, 2022 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants