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

Queue Failed_jobs issue with Exception contain UNICODE #41016

Closed
monaye opened this issue Feb 15, 2022 · 3 comments · Fixed by #41020
Closed

Queue Failed_jobs issue with Exception contain UNICODE #41016

monaye opened this issue Feb 15, 2022 · 3 comments · Fixed by #41020
Labels

Comments

@monaye
Copy link
Contributor

monaye commented Feb 15, 2022

  • Laravel Version: 8.12
  • PHP Version: 8.1.2
  • Database Driver & Version: MySQL 5.7

Description:

Failed to insert the entry into failed_jobs when Exception contains multi bytes character. In my case, Guzzle throw a ClientException with the 400 bad requests.

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE3\x81 (tr...' for column 'exception' at row 1 (SQL: insert into `failed_jobs` (`uuid`, `connection`, `queue`, `payload`, `exception`, `failed_at`) values (a2c82006-99e3-482e-9c8d-c830e4ca094b, database, default, {"uuid":"a2c82006-99e3-482e-9c8d-c830e4ca094b","displayName":"App\\Jobs\\AddCustomerToThirdParty","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":1,"maxExceptions":null,"failOnTimeout":false,"backoff":null,"timeout":null,"retryUntil":null,"data":{"commandName":"App\\Jobs\\AddCustomerToThirdParty","command":"O:32:\"App\\Jobs\\AddCustomerToThirdParty\":15:{s:48:\"\u0000App\\Jobs\\AddCustomerToThirdParty\u0000thridPartyName\";s:5:\"freee\";s:38:\"\u0000App\\Jobs\\AddCustomerToThirdParty\u0000team\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:15:\"App\\Models\\Team\";s:2:\"id\";i:5;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:42:\"\u0000App\\Jobs\\AddCustomerToThirdParty\u0000customer\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:19:\"App\\Models\\Customer\";s:2:\"id\";i:165;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:43:\"\u0000App\\Jobs\\AddCustomerToThirdParty\u0000companyId\";i:59179;s:5:\"tries\";i:1;s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}}, GuzzleHttp\Exception\ClientException: Client error: `POST https://api.freee.co.jp/api/1/partners` resulted in a `400 Bad Request` response:
{"status_code":400,"errors":[{"type":"validation","messages":["prefecture_code は null を指定することはでき� (truncated...)
 in /Users/monayewin/Documents/000_APPS/katana-clone/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /Users/monayewin/Documents/000_APPS/katana-clone/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)

Steps To Reproduce:

Just throw the exception from Job with the message that was encoded in a non-UTF8 encoded string. something like the following:

throw new Exception(mb_convert_encoding('{
                "status_code": 400,
                "errors": [
                    {
                        "type": "validation",
                        "messages": [
                            "prefecture_code は Integer で指定してください。"
                        ]
                    }
                ]
            }', "SJIS", "UTF-8"));
@driesvints
Copy link
Member

I don't get this with the following job:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class HelloWorld implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        throw new \Exception('Hello World で指定してくださ');

        // logger('Hello World で指定してくださ');
    }
}

I don't know why you're using mb_convert_encoding? Don't think you need that. You just need to put in the message as the argument of the exception. It seems to me you're trying to use an exception message in a way that's unintended.

@monaye
Copy link
Contributor Author

monaye commented Feb 15, 2022

@driesvints To reproduce, you need to encode the message to other than UTF-8.

@driesvints driesvints added the bug label Feb 15, 2022
@driesvints
Copy link
Member

Re-opening this, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants