Return Blueprint push errors via the API

This adds returning errors from the store PushBlueprint* functions, and
adds handling of the errors to the API code in preparation for new code
to check the blueprint before saving it.
This commit is contained in:
Brian C. Lane 2020-02-04 12:02:59 -08:00 committed by Ondřej Budai
parent b2f360da46
commit 8e1bc2b644
2 changed files with 22 additions and 8 deletions

View file

@ -375,9 +375,8 @@ func bumpVersion(str string) string {
return fmt.Sprintf("%d.%d.%d", v[0], v[1], v[2]+1)
}
func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) {
// FIXME: handle or comment this possible error
_ = s.change(func() error {
func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) error {
return s.change(func() error {
commit, err := randomSHA1String()
if err != nil {
return err
@ -406,9 +405,8 @@ func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) {
})
}
func (s *Store) PushBlueprintToWorkspace(bp blueprint.Blueprint) {
// FIXME: handle or comment this possible error
_ = s.change(func() error {
func (s *Store) PushBlueprintToWorkspace(bp blueprint.Blueprint) error {
return s.change(func() error {
s.Workspace[bp.Name] = bp
return nil
})

View file

@ -1161,7 +1161,15 @@ func (api *API) blueprintsNewHandler(writer http.ResponseWriter, request *http.R
}
commitMsg := "Recipe " + blueprint.Name + ", version " + blueprint.Version + " saved."
api.store.PushBlueprint(blueprint, commitMsg)
err = api.store.PushBlueprint(blueprint, commitMsg)
if err != nil {
errors := responseError{
ID: "BlueprintsError",
Msg: err.Error(),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
statusResponseOK(writer)
}
@ -1200,7 +1208,15 @@ func (api *API) blueprintsWorkspaceHandler(writer http.ResponseWriter, request *
return
}
api.store.PushBlueprintToWorkspace(blueprint)
err = api.store.PushBlueprintToWorkspace(blueprint)
if err != nil {
errors := responseError{
ID: "BlueprintsError",
Msg: err.Error(),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
statusResponseOK(writer)
}