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

Better errors #294

Merged
merged 10 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const EXPECTED_PERMISSIONS_BLOCK = [
// the environment changes in a way that would cause a replay to behave differently, e.g. upgrading to a newer
// replay-orchestrator-launcher version, or changing the version of puppeteer.
export const LOGICAL_ENVIRONMENT_VERSION = 2;

export const DOCS_URL = "https://app.meticulous.ai/docs/github-actions-v2";
41 changes: 35 additions & 6 deletions src/utils/workflow.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GitHub } from "@actions/github/lib/utils";
import { METICULOUS_LOGGER_NAME } from "@alwaysmeticulous/common";
import log from "loglevel";
import { DateTime, Duration } from "luxon";
import { DOCS_URL } from "./constants";

// The GitHub REST API will not list a workflow run immediately after it has been dispatched
const LISTING_AFTER_DISPATCH_DELAY = Duration.fromObject({ seconds: 10 });
Expand Down Expand Up @@ -42,12 +43,40 @@ export const startNewWorkflowRun = async ({
commitSha: string;
octokit: InstanceType<typeof GitHub>;
}): Promise<{ workflowRunId: number; [key: string]: unknown } | undefined> => {
await octokit.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id: workflowId,
ref,
});
try {
await octokit.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id: workflowId,
ref,
});
} catch (err: unknown) {
const logger = log.getLogger(METICULOUS_LOGGER_NAME);
if (
(err as { message?: string } | null)?.message?.includes(
"Workflow does not have 'workflow_dispatch' trigger"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error returned is a 422 returned by GH servers (https://github.com/octokit/request-error.js/blob/372097e9b16f70d4ad75089003dc9154e304faa7/src/index.ts#L16):

RequestError [HttpError]: Workflow does not have 'workflow_dispatch' trigger
     at /app/node_modules/@octokit/request/dist-node/index.js:86:21
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     at async $1e5661a16c61ad2e$export$e6c4ffd711240397 (file:///app/dist/index.mjs:291:5)
     at async $9bad9e90aadb16eb$export$fe64d28a00d9670b (file:///app/dist/index.mjs:474:25)
     at async $9bad9e90aadb16eb$export$246429c52b3b3bd3 (file:///app/dist/index.mjs:367:16)
     at async $73105851ee1dace6$export$4196946125a2d37f (file:///app/dist/index.mjs:1029:59) {
   status: 422,
   response: {
     url: <redacted>
     status: 422,
...

It has no more precise error code than that, so have to use the message unfortunately. If they change this message it'll just fall through to the more general case below, so not the end of the world.

)
) {
logger.error(
`Could not trigger a workflow run on ${commitSha} of the base branch (${ref}) to compare against, because there was no Meticulous workflow with the 'workflow_dispatch' trigger on the ${ref} branch.` +
` Screenshots of the new flows will be taken, but no comparisons will be made.` +
` If you haven't merged the PR to setup Meticulous in Github Actions to the ${ref} branch yet then this is expected.` +
` Otherwise please check that Meticulous is running on the ${ref} branch, that it has a 'workflow_dispatch' trigger, and has the appropiate permissions.` +
` See ${DOCS_URL} for the correct setup.`
);
logger.debug(err);
return undefined;
}
logger.error(
`Could not trigger a workflow run on ${commitSha} of the base branch (${ref}) to compare against.` +
` Screenshots of the new flows will be taken, but no comparisons will be made.` +
` Please check that Meticulous is running on the ${ref} branch, that it has a 'workflow_dispatch' trigger, and has the appropiate permissions.` +
` See ${DOCS_URL} for the correct setup.`,
err
);
return undefined;
}

// Wait before listing again
await delay(LISTING_AFTER_DISPATCH_DELAY);

Expand Down
Loading