UnhandledPromiseRejection in `downloadArtifact`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DefaultArtifactClient.downloadArtifact and compare its runtime authentication inputs with the ACTIONS_RUNTIME_TOKEN, ACTIONS_RUNTIME_URL, and ACTIONS_RESULTS_URL values in the reproduction script. Reproduce the failure with the provided script and confirm that the client downloads all matching artifacts without an unhandled rejection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100