Skip to content

methods that download files aren't handled correctly by GitLab::API::v4::RESTClient #48

Open
@jwrightecs

Description

@jwrightecs
Contributor

In the gitlab v4 api there are functions that download files, for example the artifact functions under jobs, this causes an error in GitLab::API::v4::RESTClient, and in gitlabl-api-v4

Actual error depends on perl version

$ perl  -Mdiagnostics -S gitlab-api-v4 job-artifacts repo/project 8003 
Redundant argument in sprintf at
	/home/gitlab/perl5/lib/perl5/GitLab/API/v4/RESTClient.pm line 66 (#1)
    (W redundant) You called a function with more arguments than other
    arguments you supplied indicated would be needed.  Currently only
    emitted when a printf-type format required fewer arguments than were
    supplied, but might be used in the future for e.g. "pack" in perlfunc.
    
Uncaught exception from user code:
	Redundant argument in sprintf at /home/gitlab/perl5/lib/perl5/GitLab/API/v4/RESTClient.pm line 66.
	GitLab::API::v4::RESTClient::croakf("Error decoding JSON (%s %s %s): ", "GET", "https://code.ecstuning.io/api/v4/projects/repo%2Fproject/jobs/8003"..., 200, "malformed JSON string, neither tag, array, object, number, st"...) called at /home/gitlab/perl5/lib/perl5/GitLab/API/v4/RESTClient.pm line 243
	GitLab::API::v4::RESTClient::catch {...} ("malformed JSON string, neither tag, array, object, number, st"...) called at /home/gitlab/perl5/lib/perl5/Try/Tiny.pm line 123
	Try::Tiny::try(CODE(0x55ceea834e08), Try::Tiny::Catch=REF(0x55cee96f1710)) called at /home/gitlab/perl5/lib/perl5/GitLab/API/v4/RESTClient.pm line 245
	GitLab::API::v4::RESTClient::request(GitLab::API::v4::RESTClient=HASH(0x55cee9d42de0), "GET", "projects/:project_id/jobs/:job_id/artifacts", ARRAY(0x55ceea79c2c0), HASH(0x55ceea7c6200)) called at /home/gitlab/perl5/lib/perl5/GitLab/API/v4.pm line 123
	GitLab::API::v4::_call_rest_client(GitLab::API::v4=HASH(0x55ceea813068), "GET", "projects/:project_id/jobs/:job_id/artifacts", ARRAY(0x55ceea79c2c0), HASH(0x55ceea7c6200)) called at /home/gitlab/perl5/lib/perl5/GitLab/API/v4.pm line 4062
	GitLab::API::v4::job_artifacts(GitLab::API::v4=HASH(0x55ceea813068), "repo/project", 8003) called at /home/gitlab/perl5/bin/gitlab-api-v4 line 115

(Older versions without the 'redundant' warning class)

$ perl -Mdiagnostics -S gitlab-api-v4 job-artifacts repo/project 8003
Uncaught exception from user code:
        malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "PK\x{3}\x{4}\x{14}\x{0}...") at /usr/local/share/perl5/GitLab/API/v4/RESTClient.pm  line 177.
 at /usr/local/share/perl5/GitLab/API/v4/RESTClient.pm line 177.
        GitLab::API::v4::RESTClient::request(GitLab::API::v4::RESTClient=HASH(0x1ef65a0), "GET", "projects/:project_id/jobs/:job_id/artifacts", ARRAY(0x2a3c448), HASH(0x23f9558)) called at /usr/loc
al/share/perl5/GitLab/API/v4.pm line 123
        GitLab::API::v4::_call_rest_client(GitLab::API::v4=HASH(0x23cd8e8), "GET", "projects/:project_id/jobs/:job_id/artifacts", ARRAY(0x2a3c448), HASH(0x23f9558)) called at /usr/local/share/perl5
/GitLab/API/v4.pm line 3872
        GitLab::API::v4::job_artifacts(GitLab::API::v4=HASH(0x23cd8e8), "repo/project", 8003) called at /usr/local/bin/gitlab-api-v4 line 117

Similarly, using the module directly:

$ reply
0> use GitLab::API::v4::Config; use GitLab::API::v4;
1> my $api = GitLab::API::v4->new(  GitLab::API::v4::Config->new->args );
$res[0] = bless( {
         '_access_token_closure' => sub { "DUMMY" },
         '_private_token_closure' => sub { "DUMMY" },
         'retries' => 0,
         'url' => 'https://code.gitlab.io/api/v4'
       }, 'GitLab::API::v4' )

2>  my $artifacts = $api->job_artifacts('repo/project', 8003);
Redundant argument in sprintf at /home/gitlab/perl5/lib/perl5/GitLab/API/v4/RESTClient.pm line 66.
3> 

Activity

sur5r

sur5r commented on Oct 25, 2024

@sur5r

I tried adding $options->{decode}=0 after

my $options = {};
which prevents the error.

However, the artifact (a ZIP archive in my case) is printed to stdout (good) but with non-printable characters escaped as \uXXXX and double quotes around it (not so good).

It seems the handling of non-JSON replies needs to be rethought.

added a commit that references this issue on Oct 26, 2024
e356729
linked a pull request that will close this issue on Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sur5r@jwrightecs

      Issue actions

        methods that download files aren't handled correctly by GitLab::API::v4::RESTClient · Issue #48 · bluefeet/GitLab-API-v4