Skip to content

Conversation

@damienmckenna
Copy link

Some countries will have state_or_province codes that are longer than two characters. FedEx's API will fail if this value is longer than two. Truncate the string to two characters to avoid such errors.

Resolves #42.

Some countries will have state_or_province codes that are longer than two characters. FedEx's API will fail if this value is longer than two. Truncate the string to two characters to avoid such errors.
@gemini-code-assist
Copy link

Summary of Changes

Hello @damienmckenna, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to ensure compatibility with the FedEx API. It addresses an issue where FedEx's API would reject requests containing state_or_province codes longer than two characters. The change involves programmatically truncating these codes to their first two characters, thereby preventing API errors and ensuring smooth operation when interacting with FedEx services.

Highlights

  • FedEx API Compatibility: Implemented truncation of the state_or_province code to two characters to ensure compliance with FedEx API requirements.
  • Error Prevention: This change prevents API failures that previously occurred when state_or_province values exceeded two characters, ensuring smoother integration with FedEx services.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to fix an issue with the FedEx API by truncating the state_or_province field to two characters. While the intention is good, the current implementation has a critical flaw: it applies this truncation universally, which will corrupt addresses for countries that use longer state/province codes (e.g., Australia). My review provides feedback on how to address this by making the logic conditional on the country code to avoid silent data corruption and potential shipping failures.

Comment on lines 84 to 85
// Truncate the state/provice code to work around a limitation in FedEx's API.
$address['stateOrProvinceCode'] = substr($this->state_or_province, 0, 2);

Choose a reason for hiding this comment

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

critical

This change introduces a significant issue by unconditionally truncating the state_or_province to two characters. This will lead to incorrect addresses for countries that use state/province codes longer than two characters, such as Australia (e.g., 'NSW', 'QLD'). Sending incorrect data is often worse than getting an API error, as it can lead to failed deliveries or other hard-to-debug issues.

A safer approach would be to make the truncation logic conditional on the country code ($this->country_code). For example, you could apply this only for countries where you are certain a two-character code is required, like the US and Canada. Your implementation could look like this, replacing the current line:

if (!empty($this->country_code) && in_array($this->country_code, ['US', 'CA'])) {
    $address['stateOrProvinceCode'] = substr($this->state_or_province, 0, 2);
} else {
    $address['stateOrProvinceCode'] = $this->state_or_province;
}

Also, consider using mb_substr() for multi-byte character safety, although it's less critical for state codes.

Finally, there's a typo in the comment on line 84: provice should be province.

Copy link
Author

Choose a reason for hiding this comment

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

I fixed the comment typo.

The suggestion for making the logic conditional misses the point - it's not that the string must be two characters long, it's that it must not be longer than two digits, so will fail on valid strings like "QLD" for Queensland. In this case working around an API limitation is a simple approach that catches all scenarios.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error if state_or_province is longer than 2 characters

1 participant