Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
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.
  • Loading branch information
aeisenberg committed Jan 21, 2022
commit 752ae5743f660abf77f426071c8a73dfdf3b8a0a
19 changes: 14 additions & 5 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,25 @@ export class GitHubFeatureFlags implements FeatureFlags {
);
return response.data;
} catch (e) {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these feature flags disabled in the event of a transient error could
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
// the feature flags.
throw new Error(
`Encountered an error while trying to load feature flags: ${e}`
);
if (
e instanceof Error &&
e.message.includes("Resource not accessible by integration")
Comment thread
henrymercer marked this conversation as resolved.
Outdated
) {
throw new Error(
`Resource not accessible by integration. This usually means that your ` +
`workflow is missing the required security-events write permissions. ` +
`See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions ` +
`for more information.`
Comment thread
henrymercer marked this conversation as resolved.
Outdated
);
} else {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these feature flags disabled in the event of a transient error could
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
// the feature flags.
throw new Error(
`Encountered an error while trying to load feature flags: ${e}`
);
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ async function run() {
repositoryNwo,
logger
);
void featureFlags.preloadFeatureFlags();

try {
await featureFlags.preloadFeatureFlags();
Comment thread
henrymercer marked this conversation as resolved.
Outdated

const workflowErrors = await validateWorkflow();

if (
Expand Down