Skip to content

UnhandledPromiseRejection in downloadArtifact #2031

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

Open
yury-s opened this issue Apr 21, 2025 · 0 comments
Open

UnhandledPromiseRejection in downloadArtifact #2031

yury-s opened this issue Apr 21, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@yury-s
Copy link

yury-s commented Apr 21, 2025

Describe the bug
While running await client.downloadArtifact(...) I'm getting the following exception:

::debug::Artifact destination folder does not exist, creating: /Users/<user>/sandbox/octokit/all-blob-reports/blob-report-ubuntu-latest-node18-1
node:internal/process/promises:392
      new UnhandledPromiseRejection(reason);
      ^

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "InvalidTokenError: Invalid token specified: Cannot read properties of undefined (reading 'replace')".
    at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
    at processPromiseRejections (node:internal/process/promises:475:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
  code: 'ERR_UNHANDLED_REJECTION'
}

To Reproduce
Run the following script locally with your token:

import { DefaultArtifactClient, FindOptions } from '@actions/artifact';
import * as core from '@actions/core';
import * as fs from 'fs';
import * as path from 'path';


process.env.ACTIONS_STEP_DEBUG = 'true';
process.env.GITHUB_TOKEN =  'xxx';
process.env.ACTIONS_RUNTIME_TOKEN = process.env.GITHUB_TOKEN;
process.env.ACTIONS_RUNTIME_URL='http://localhost/fake';
process.env.ACTIONS_RESULTS_URL='http://localhost/fake_results';

function getGithubToken() {
  const token = process.env.GITHUB_TOKEN || core.getInput('github-token');
  if (!token) {
    core.setFailed('Missing "github-token" input');
    throw new Error('Missing "github-token" input');
  }
  return token;
}

async function downloadArtifacts(runId: number, dir: string) {

  const client = new DefaultArtifactClient();
  const findBy: FindOptions['findBy'] = {
    workflowRunId: runId,
    repositoryOwner: 'microsoft',
    repositoryName: 'playwright',
    token: getGithubToken(),
  };

  const allArtifacts = await client.listArtifacts({
    latest: true,
    findBy
  });
  const artifacts = allArtifacts.artifacts.filter(a => a.name.startsWith('blob-report-ubuntu-latest-'));
  console.log(artifacts.map(a => a.name));

  const prefix = path.resolve(process.cwd(), dir);
  await fs.promises.mkdir(prefix, { recursive: true });
  for (const artifact of artifacts) {
    const filePath = path.join(prefix, `${artifact.name}`);
    console.log(`* Downloading ${artifact.name}.zip to ${filePath}`);
    const result = await client.downloadArtifact(artifact.id,
      {
        ...findBy,
        path: filePath,
      }
    );
  }
}

downloadArtifacts(14498356788, 'all-blob-reports');

Expected behavior
All artifacts are downloaded.

Desktop (please complete the following information):

  • OS: maOS 15.4.1
  • Node.js v22.11.0
@yury-s yury-s added the bug Something isn't working label Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant