Skip to content

Commit

Permalink
Merge pull request #552 from humblenginr/error_handling_registration
Browse files Browse the repository at this point in the history
Enhance Error Handling for Registration
  • Loading branch information
Jougan-0 authored Aug 8, 2024
2 parents b1794be + 91ccbc5 commit 077f1b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion models/registration/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type RegistrationErrorStore interface {
// Anything that can be parsed into a packagingUnit is a RegisterableEntity in Meshery server
type RegisterableEntity interface {
/*
1. `err` - this is a breaking error, which signifies that the given entity is invalid
1. `err` - this is a breaking error, which signifies that the given entity is invalid and cannot be registered
2. Errors encountered while parsing items into meshmodel entites are stored in the RegistrationErrorStore
*/
PkgUnit(RegistrationErrorStore) (packagingUnit, error)
Expand Down
18 changes: 8 additions & 10 deletions models/registration/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,29 @@ func NewRegistrationHelper(svgBaseDir string, regm *meshmodel.RegistryManager, r
/*
Register will accept a RegisterableEntity (dir, tar or oci for now).
*/
func (rh *RegistrationHelper) Register(entity RegisterableEntity) error {
func (rh *RegistrationHelper) Register(entity RegisterableEntity) {
// get the packaging units
pu, err := entity.PkgUnit(rh.regErrStore)
if err != nil {
// given input is not a valid model, or could not walk the directory
return err
return
}
// fmt.Printf("Packaging Unit: Model name: %s, comps: %d, rels: %d\n", pu.model.Name, len(pu.components), len(pu.relationships))
return rh.register(pu)
rh.register(pu)
}

/*
register will return an error if it is not able to register the `model`.
If there are errors when registering other entities, they are handled properly but does not stop the registration process.
*/
func (rh *RegistrationHelper) register(pkg packagingUnit) error {
func (rh *RegistrationHelper)register(pkg packagingUnit) {
// 1. Register the model
model := pkg.model

// Dont register anything else if registrant is not there
if model.Registrant.Hostname == "" {
err := ErrMissingRegistrant(model.Name)
rh.regErrStore.InsertEntityRegError(model.Registrant.Hostname, "", entity.Model, model.Name, err)
return err
rh.regErrStore.InsertEntityRegError(model.Registrant.Hostname, "",entity.Model, model.Name, err)
return
}
writeAndReplaceSVGWithFileSystemPath(model.Metadata, rh.svgBaseDir, model.Name, model.Name) //Write SVG for models
_, _, err := rh.regManager.RegisterEntity(
Expand All @@ -62,8 +61,8 @@ func (rh *RegistrationHelper) register(pkg packagingUnit) error {
// If model cannot be registered, don't register anything else
if err != nil {
err = ErrRegisterEntity(err, string(model.Type()), model.DisplayName)
rh.regErrStore.InsertEntityRegError(model.Registrant.Hostname, "", entity.Model, model.Name, err)
return err
rh.regErrStore.InsertEntityRegError(model.Registrant.Hostname, "",entity.Model, model.Name, err)
return
}

hostname := model.Registrant.Hostname
Expand Down Expand Up @@ -93,5 +92,4 @@ func (rh *RegistrationHelper) register(pkg packagingUnit) error {
rh.regErrStore.InsertEntityRegError(hostname, modelName, entity.RelationshipDefinition, rel.ID.String(), err)
}
}
return nil
}

0 comments on commit 077f1b5

Please sign in to comment.