-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore(src/clients): improved error handling #28
base: main
Are you sure you want to change the base?
Conversation
src/clients.ts
Outdated
|
||
const spawn = spawnSync('gh', ['repo', 'view', '--json', 'nameWithOwner'], { stdio: ['ignore', 'pipe', 'pipe'] }); | ||
const stderr = spawn.stderr?.toString(); | ||
if (stderr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of this. Can’t we get an exit code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. We can throw on non 0 exit codes. Are you cool with keeping the stderr output in the message or would you rather not 'pipe'
it?
const spawn = spawnSync('gh', args, { input: value, stdio: ['pipe', 'inherit', 'pipe'] });
if (spawn.status !== 0) {
throw new Error(`Failed to store secret '${name}' in repository '${repository}'. ${spawn.stderr?.toString()}`);
}
Summary
This PR adds improved error handling when interfacing with the GitHub CLI or AWS SecretsManager.
When I first used this project I did not have permission to one of the repos it was trying to swap secrets for. It silently failed and caused trouble until we noticed the issue. This will hopefully prevent that from happening again.