EasyPost/easypost-php

Fatal error: Wrong parameters for Exception

Closed this issue · 11 comments

Fatal error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in /app/vendor/easypost/easypost-php/lib/EasyPost/Error.php on line 16

We recently started seeing this fatal popup inside a few of our services. Unfortunately I don't have any more details yet, but my guess is that the problem is sneaking in here:

throw new Error(is_array($response['error']) ? $response['error']['message'] : (!empty($response['error']) ? $response['error'] : ""), $httpStatus, $httpBody);

as it looks like that's the only new Error call that doesn't explicitly pass a string as $message. Could the $response['error']['message'] also be an array (json object) from the API?

@mattgrosse if you could provide us a way to recreate this error (params, code snippet, endpoint you are trying to hit, etc), I'd be happy to take a look into getting a fix out for this.

I'm working on getting an example to recreate this, though I think it's related to address verification. One of the scripts that failed only uses the \EasyPost\Address class, as follows:

        $verifications = ["delivery"];

        if ($request->shipTo->country == 'US') {
            $verifications[] = "zip4";
        }

        $address = \EasyPost\Address::create(
            [
                "name"    => $request->shipTo->fname . ' ' . $request->shipTo->lname,
                "street1" => $request->shipTo->address1,
                "street2" => $request->shipTo->address2 ? $request->shipTo->address2 : null,
                "city"    => $request->shipTo->city,
                "state"   => $request->shipTo->state,
                "zip"     => $request->shipTo->postalCode,
                "country" => $request->shipTo->country,
                "phone"   => $request->shipTo->phone,
                "verify"  => $verifications,
                "verify_strict" => false,
            ]
        );

bump! Same error here

@mattgrosse @guillermodoghel I'm sadly not able to reproduce this error with the information provided on either v3.4.1 or v3.4.5 of this client library. Here is a full snippet I tried:

<?php
require_once '/Users/jhammond/git/easypost/easypost-tools/vendor/autoload.php';
use Dotenv\Dotenv;
use EasyPost\EasyPost;
use EasyPost\Address;
use EasyPost\Error;

$dotenv = Dotenv::createImmutable('/Users/jhammond/git/easypost/easypost-tools');
$dotenv->load();
EasyPost::setApiKey(getenv('EASYPOST_PROD_API_KEY'));

try {
    $verifications = ["delivery"];
    $verifications[] = "zip4";

    $address = Address::create(
        [
            "verify"  => $verifications,
            "verify_strict" => false,
            "street1" => "417 MONTGOMERY ST",
            "street2" => "FL 5",
            "city"    => "San Francisco",
            "state"   => "CA",
            "zip"     => "94104",
            "country" => "US",
            "company" => "EasyPost",
            "phone"   => "415-123-4567"
        ]
    );

    echo $address;
} catch (Error $exception) {
    echo $exception;
}

Could I have you provide me the PHP client library versions you are using and an address that fails to create properly?

I should note that we're running PHP 5.6.40 and version 3.4.5 of this lib.

I'm still working on getting an example of this failing, but haven't been able to reproduce it yet. Our service works on a queue of items, and subsequent passes (after the fatal) seem to be getting through the queue. So it feels like something intermittent, perhaps an API timeout? But that's just a guess. I'll keep updating if I find something.

Thank you! For clarity, I'm using PHP 7.4.9. I am also starting to believe this is an intermittent issue of the API vs the client library - a particular error that isn't being caught properly by this library but isn't thrown frequently enough either that we've been able to add the right logic here to catch it.

Keep me appraised of any developments on what you find.

We believe we have identified the issue which indeed exhibits itself intermittently and are working on a solution - this however is most likely not an issue with this client library but with the core EasyPost API. I'll make sure to update this thread with more information as it becomes available.

we are running PHP Version => 5.6.38

and is impossible for us to change that.

what we have got from support and seems suspicious is this response:

Screen Shot 2020-09-24 at 16 07 11

what we have noted is, if we repeat that call, eventually it would pass. Looks like some exception that is not caught by the library and somehow crashes the whole thing, but it seems as a third party problem, because on a retry it works fine

@Justintime50 thanks for your help on this. I'll post an update here if we see anything else, but I don't think that fatal has happened since you guys started to work on the fix. I did see this response come up in our purchase label queue:

The load balancer was unable to handle this request

I don't remember seeing that one before, so maybe that's what got updated on the API side. Either way, things seem better now!

@mattgrosse the load balancer issue was unrelated to the above, you can read about it here: https://www.easypoststatus.com/incidents/04xpbdvdszb9 - it's been resolved.

As for the address verification issue, it's been identified and is under review as we speak. I'll let you know when a fix has been deployed.

Hey @mattgrosse and @guillermodoghel, we've deployed a fix for this issue on the API side - you should no longer see this error while using address verification! If you have further in relation to this, please feel free to email support@easypost.com and our support team can assist you from there.

Thanks for your patience and submitting this issue!