Skip to content

Commit 752ae57

Browse files
committed
Ensure loadApiError is caught
And add a better error message. By using `void` instead of `await`, any error thrown is not caught by surrounding try-catch blocks. I could continue to use `void` and explicitly handle any thrown errors by using `.catch`, but most likely the time savings is minimal and this makes the code more complex.
1 parent 0dabead commit 752ae57

6 files changed

Lines changed: 38 additions & 16 deletions

File tree

lib/feature-flags.js

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/feature-flags.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,25 @@ export class GitHubFeatureFlags implements FeatureFlags {
6666
);
6767
return response.data;
6868
} catch (e) {
69-
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
70-
// Considering these feature flags disabled in the event of a transient error could
71-
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
72-
// the feature flags.
73-
throw new Error(
74-
`Encountered an error while trying to load feature flags: ${e}`
75-
);
69+
if (
70+
e instanceof Error &&
71+
e.message.includes("Resource not accessible by integration")
72+
) {
73+
throw new Error(
74+
`Resource not accessible by integration. This usually means that your ` +
75+
`workflow is missing the required security-events write permissions. ` +
76+
`See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions ` +
77+
`for more information.`
78+
);
79+
} else {
80+
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
81+
// Considering these feature flags disabled in the event of a transient error could
82+
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
83+
// the feature flags.
84+
throw new Error(
85+
`Encountered an error while trying to load feature flags: ${e}`
86+
);
87+
}
7688
}
7789
};
7890

src/init-action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ async function run() {
143143
repositoryNwo,
144144
logger
145145
);
146-
void featureFlags.preloadFeatureFlags();
147146

148147
try {
148+
await featureFlags.preloadFeatureFlags();
149+
149150
const workflowErrors = await validateWorkflow();
150151

151152
if (

0 commit comments

Comments
 (0)