woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
321 stars 113 forks source link

Shipping labels: JSON parsing error after creating a label successfully #11817

Open jaclync opened 10 months ago

jaclync commented 10 months ago

Describe the bug

With WooCommerce Shipping & Tax version 2.4.2 (and WC v8.4), the label response after a successful purchase results in a JSON parsing error because some of the items in labelsData have a null carrier_id while the attribute ShippingLabel.carrierID is expected to be non-nil. It's odd that there's only one product in the order/package, but more than one item in the labelsData.

{
  "data" : {
    "orderId" : 4192,
    "labelsData" : [
      {
        "currency" : "USD",
        "product_names" : [
          "(Sale!) AirPods Pro"
        ],
        "expiry_date" : 1721810976000,
        "product_ids" : [
          3685
        ],
        "service_name" : "USPS - Media Mail",
        "tracking" : "9449000106025012573640",
        "label_id" : 2996,
        "created_date" : 1706258977000,
        "package_name" : "Empty box",
        "is_letter" : false,
        "receipt_item_id" : 24767539,
        "is_commercial_invoice_submitted_electronically" : false,
        "created" : 1706258972777,
        "refundable_amount" : 4.8700000000000001,
        "commercial_invoice_url" : "",
        "carrier_id" : "usps",
        "rate" : 4.8700000000000001,
        "status" : "PURCHASED",
        "main_receipt_id" : 20140866
      },
      {
        "product_names" : [
          "(Sale!) AirPods Pro"
        ],
        "product_ids" : [
          3685
        ],
        "service_name" : "USPS - Media Mail",
        "tracking" : null,
        "label_id" : 2680,
        "package_name" : "Cool box",
        "is_letter" : false,
        "is_commercial_invoice_submitted_electronically" : "",
        "created" : 1692685421649,
        "refundable_amount" : 0,
        "commercial_invoice_url" : "",
        "carrier_id" : null,
        "status" : "PURCHASE_IN_PROGRESS"
      },
      {
        "currency" : "USD",
        "product_names" : [
          "(Sale!) AirPods Pro"
        ],
        "expiry_date" : 1705221986000,
        "product_ids" : [
          3685
        ],
        "service_name" : "USPS - Media Mail",
        "tracking" : "9449000106025236487952",
        "label_id" : 2653,
        "created_date" : 1689669987000,
        "package_name" : "FUN BOX",
        "is_letter" : false,
        "receipt_item_id" : 24709993,
        "is_commercial_invoice_submitted_electronically" : false,
        "created" : 1689669982976,
        "refundable_amount" : 4.6699999999999999,
        "commercial_invoice_url" : "",
        "carrier_id" : "usps",
        "rate" : 4.6699999999999999,
        "status" : "PURCHASED",
        "main_receipt_id" : 20085932
      }
    ],
    "success" : true,
    "formData" : {
      "origin" : {
        "phone" : "6506658565",
        "address" : "331 19th Ave",
        "country" : "US",
        "city" : "San Francisco",
        "company" : "fun testing",
        "postcode" : "94111",
        "address_2" : "",
        "name" : "Jaclyn Chen",
        "state" : "CA"
      },
      "destination" : {
        "phone" : "6505253523",
        "city" : "San Francisco ",
        "country" : "US",
        "address" : "357 19th Ave",
        "company" : "",
        "postcode" : "94111",
        "address_2" : "",
        "state" : "CA",
        "name" : " "
      },
      "order_id" : 4192,
      "rates" : {
        "selected" : {

        }
      },
      "selected_packages" : {
        "default_box" : {
          "box_id" : "not_selected",
          "height" : 0,
          "length" : 0,
          "id" : "default_box",
          "weight" : 0.29999999999999999,
          "width" : 0,
          "items" : [
            {
              "quantity" : 1,
              "description" : "(Sale!) AirPods Pro",
              "width" : 2,
              "url" : "https://funtesting.toys/wp-admin/post.php?post=3685&action=edit",
              "weight" : 0.29999999999999999,
              "length" : 10,
              "origin_country" : "US",
              "value" : 250,
              "product_id" : 3685,
              "height" : 5,
              "hs_tariff_number" : "",
              "name" : "1235test - (Sale!) AirPods Pro"
            }
          ]
        }
      },
      "origin_normalized" : true,
      "destination_normalized" : true,
      "is_packed" : true
    },
    "paperSize" : "legal",
    "storeOptions" : {
      "origin_country" : "US",
      "dimension_unit" : "in",
      "currency_symbol" : "$",
      "weight_unit" : "kg"
    },
    "canChangeCountries" : true
  }
}

Logging error:

🔵 Tracked api_json_parsing_error, properties: [AnyHashable("was_ecommerce_trial"): false, AnyHashable("error_description"): "Swift.DecodingError.valueNotFound(Swift.Array<Swift.String>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: \"data\", intValue: nil), CodingKeys(stringValue: \"labelsData\", intValue: nil), _JSONKey(stringValue: \"Index 1\", intValue: 1), CodingKeys(stringValue: \"carrier_id\", intValue: nil)], debugDescription: \"Cannot get unkeyed decoding container -- found null value instead\", underlyingError: nil))", AnyHashable("error_code"): "4865", AnyHashable("error_domain"): "NSCocoaErrorDomain", AnyHashable("debug_decoding_path"): "data.labelsData.carrier_id", AnyHashable("plan"): "business-bundle", AnyHashable("path"): "label/4192", AnyHashable("entity"): "OrderShippingLabelListResponse", AnyHashable("site_url"): "https://funtesting.toys", AnyHashable("is_wpcom_store"): true, AnyHashable("debug_decoding_description"): "Cannot get unkeyed decoding container -- found null value instead", AnyHashable("store_id"): "6af09011-6ee4-461b-8b06-8a01a72c4e18", AnyHashable("blog_id"): 161199960]
<> Mapping Error: valueNotFound(Swift.Array<Swift.String>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "data", intValue: nil), CodingKeys(stringValue: "labelsData", intValue: nil), _JSONKey(stringValue: "Index 1", intValue: 1), CodingKeys(stringValue: "carrier_id", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead", underlyingError: nil))

The labels are shown in core:

Screenshot 2024-01-26 at 5 13 47 PM

To Reproduce Steps to reproduce the behavior:

Feel free to ping me if you can't repro in your store, I can invite you to the test store that I can reproduce.

Screenshots

https://github.com/woocommerce/woocommerce-ios/assets/1945542/aa792860-2caa-41a5-9117-e08910b79989

Expected behavior

The shipping label fetching should succeed after a successful purchase.

Isolating the problem (mark completed items with an [x]):

Mobile Environment Please include:

WordPress Environment

WooCommerce Shipping & Tax version 2.4.2 (and WC v8.4)
jaclync commented 10 months ago

Asked the Woo shipping dev team in p1706495687440749-slack-C04KWSNPSE5