Skip to content

Helping developer to debug bad API calls #879

@matks

Description

@matks

Hi !

I report a very weird bug 😅 ... very weird because I use some code 1 month ago, everything is great 👍 and now same code fails.

Very simple usecase: create new file into repository. I used my fork of php-github-api as example.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$token = 'XXX';
$client->authenticate($token, null, Github\Client::AUTH_HTTP_TOKEN);

$committer = array('name' => 'matks', 'email' => '[email protected]');

$fileInfo = $client->api('repo')->contents()
    ->create('matks', 'php-github-api', 'test.md', 'a', 'test', 'master', $committer);

Code worked some months ago, I want to reuse it, now it fails with following error:

PHP Fatal error:  Uncaught Github\Exception\ErrorException: Problems parsing JSON in /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php:51
Stack trace:
#0 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(34): Github\HttpClient\Plugin\GithubExceptionThrower->Github\HttpClient\Plugin\{closure}(Object(GuzzleHttp\Psr7\Response))
#1 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php(106): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure))
#2 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/client-common/src/Plugin/VersionBridgePlugin.php(19): Github\HttpClient\Plugin\GithubExceptionThrower->doHandleRequest(Object(GuzzleHttp\Psr7\Request), Object(Closure), Object(Closure))
#3 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/client-common/src/ in /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php on line 51

Fatal error: Uncaught Github\Exception\ErrorException: Problems parsing JSON in /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php:51
Stack trace:
#0 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(34): Github\HttpClient\Plugin\GithubExceptionThrower->Github\HttpClient\Plugin\{closure}(Object(GuzzleHttp\Psr7\Response))
#1 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php(106): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure))
#2 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/client-common/src/Plugin/VersionBridgePlugin.php(19): Github\HttpClient\Plugin\GithubExceptionThrower->doHandleRequest(Object(GuzzleHttp\Psr7\Request), Object(Closure), Object(Closure))
#3 /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/php-http/client-common/src/ in /Users/mFerment/www/perso/prestashop-repos-bulk-editor/vendor/knplabs/github-api/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php on line 51

I tried to debug this "Problems parsing JSON" and found different people having it, but nothing similar to my very simple usecase. The things I found were mostly people building their requests to GitHub API manually with cURL or Postman and they had to require some specific http header or pass JSON in body or in param to make it work. Which is what php-github-api should do, right 😅

Because I have "the code worked 1 month ago and now it fails" I guess 2 possibilities:

  • github API was updated and it's a bug
  • php-github-api got a new version, I upgraded it through Composer and I found a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions