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

chore(src/clients): improved error handling #28

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ryparker
Copy link

@ryparker ryparker commented Nov 22, 2022

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.

@ryparker ryparker self-assigned this Nov 22, 2022
@ryparker ryparker added enhancement New feature or request and removed enhancement New feature or request labels Nov 22, 2022
@ryparker ryparker marked this pull request as draft November 22, 2022 01:45
@ryparker ryparker marked this pull request as ready for review November 22, 2022 03:37
@ryparker ryparker requested a review from a team November 22, 2022 03:38
@ryparker ryparker changed the title feat(src/clients): improved error handling chore(src/clients): improved error handling Nov 22, 2022
src/clients.ts Outdated

const spawn = spawnSync('gh', ['repo', 'view', '--json', 'nameWithOwner'], { stdio: ['ignore', 'pipe', 'pipe'] });
const stderr = spawn.stderr?.toString();
if (stderr) {
Copy link
Contributor

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?

Copy link
Author

@ryparker ryparker Nov 22, 2022

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()}`);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants