Skip to content

Conversation

@LawnGnome
Copy link
Contributor

This turned out to be a nicer cleanup than I expected: the parse and validate helper functions in cmd/src were separate for mostly historical reasons, but now we can unify them.

Fixes sourcegraph/sourcegraph#14249.

Fixes sourcegraph/sourcegraph#14249.
@LawnGnome LawnGnome requested a review from a team October 16, 2020 01:18
Comment on lines +292 to +315
func campaignsParseSpec(out *output.Output, svc *campaigns.Service, input io.ReadCloser) (*campaigns.CampaignSpec, string, error) {
spec, raw, err := svc.ParseCampaignSpec(input)
if err != nil {
if merr, ok := err.(*multierror.Error); ok {
block := out.Block(output.Line("\u274c", output.StyleWarning, "Campaign spec failed validation."))
defer block.Close()

for i, err := range merr.Errors {
block.Writef("%d. %s", i+1, err)
}

return nil, "", &exitCodeError{
error: nil,
exitCode: 2,
}
} else {
// This shouldn't happen; let's just punt and let the normal
// rendering occur.
return nil, "", err
}
}

return spec, raw, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering if we should incorporate this logic into ParseCampaignSpec, then we wouldn't need this function that gets passed in a service, and it can't be forgotten. Are there use-cases where we explicitly would not want to have this error prettify logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's basically a layering thing: I don't want internal/campaigns (in this case, the Service methods) to have any specific knowledge of internal/output, so this code lives here to basically handle the rendering of any errors. This function is used by each of the campaign commands that have to parse a spec file, though, so it's still shared.

@LawnGnome LawnGnome merged commit 0dd874f into main Oct 20, 2020
@LawnGnome LawnGnome deleted the aharvey/migrate-validation branch October 20, 2020 03:58
scjohns pushed a commit that referenced this pull request Apr 24, 2023
Fixes sourcegraph/sourcegraph#14249.
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.

campaigns: move unmarshalValidate, with its yaml/json stuff, into cschema

4 participants