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 error handling when SHASUM file is missing #1439

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

diofeher
Copy link
Member

@diofeher diofeher commented Jan 13, 2025

Closes #280

Description

  • Removed a few extra spaces on the texts
  • Add output.json as default on this script
  • Removed an extra slash on the github-action bot comment (Provider: terraform-provider-nix-signature #1438) after the src.
  • Provided a better error message when shaSum file is missing.

Tested with https://github.com/diofeher/terraform-provider-nix-signature/releases/tag/v0.1.1

Screenshot 2025-01-13 at 19 04 00

Signed-off-by: Diogenes Fernandes <[email protected]>
@abstractionfactory abstractionfactory marked this pull request as draft January 13, 2025 22:21
@abstractionfactory
Copy link
Contributor

This PR seems to have commented-out code, moving back to draft.

Signed-off-by: Diogenes Fernandes <[email protected]>
@diofeher diofeher marked this pull request as ready for review January 13, 2025 22:25
Copy link
Contributor

@abstractionfactory abstractionfactory left a comment

Choose a reason for hiding this comment

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

I'm not sure if it's possible, but it would be nice if this functionality reported back as a comment to the submitter because it would make debugging issues easier. Then again, most of this repository would need to be moved over to libregistry anyway, so maybe we can do it as part of that move.

@@ -28,7 +28,7 @@ func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

repository := flag.String("repository", "", "The provider repository to add")
outputFile := flag.String("output", "", "Path to write JSON result to")
outputFile := flag.String("output", "output.json", "Path to write JSON result to")
Copy link
Member Author

Choose a reason for hiding this comment

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

It's just because if you don't specify the output flag, the program panics next to the JSON function that writes to this output.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I'm adding the default in case someone doesn't pass the flag

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather the program exit early if the flag is not provided

@@ -28,7 +28,7 @@ func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

repository := flag.String("repository", "", "The provider repository to add")
outputFile := flag.String("output", "", "Path to write JSON result to")
outputFile := flag.String("output", "output.json", "Path to write JSON result to")
Copy link
Member Author

Choose a reason for hiding this comment

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

It's just because if you don't specify the output flag, the program panics next to the JSON function that writes to this output.

@diofeher
Copy link
Member Author

diofeher commented Jan 14, 2025

Your review makes sense @abstractionfactory ! I will work later to port this code to libregistry, and add the code to report back as a comment in the registry repo. I'll leave this PR open for now for changing the Github actions to report the comment.

@abstractionfactory
Copy link
Contributor

@diofeher I think we can skip the libregistry part for now, we still need to figure out what our roadmap is to get that going. However, I'd still like to get this merged before that.

@@ -13,7 +13,7 @@ func (p Provider) GetSHASums(shaFileDownloadUrl string) (map[string]string, erro
return nil, fmt.Errorf("failed to download asset contents: %w", assetErr)
}
if contents == nil {
return nil, nil
return nil, fmt.Errorf("SHASUM file is empty or missing: %s", shaFileDownloadUrl)
Copy link
Member

Choose a reason for hiding this comment

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

There was a very specific reason I didn't return an error here. We don't want new releases (with missing shasums) to cause a whole provider to stop updating. A lot of providers have historical releases that we scan from time to time which would percolate this error back up the stack.

We either need to add a flag to the calls tack to make this a true error or not, or create a specific error type that is handled correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense @cam72cam

Should we put what your explained to me in this part of the code as well? I feel this is important information that should be in a comment

Copy link
Member Author

Choose a reason for hiding this comment

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

So this seems to be more complicated than I thought, because all workflows are using this function, so we would need to identify what exact behavior we need when adding a provider from Github Actions or from other places. I'm gonna do a research later on this.

Copy link
Member

Choose a reason for hiding this comment

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

A comment is a great idea, a lot of this was hastily adapted from prototype so context may be missing for quirks like this.

@diofeher diofeher marked this pull request as draft January 31, 2025 20:48
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.

Better error message for missing SHA256SUMS file
3 participants