Skip to content

Commit

Permalink
Consider PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Mar 14, 2024
1 parent e997e4d commit d6bc223
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions manifest/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *manifestConverter) validateManifest(manif *Manifest) error {
}
case "":
if s.Use == "" {
return fmt.Errorf("stream %q: missing 'use' attribute for a module not specifying any kind", s.Name)
return fmt.Errorf("module kind not specified for %q", s.Name)
}

if err := validateModuleWithUse(s); err != nil {
Expand All @@ -88,6 +88,7 @@ func (r *manifestConverter) validateManifest(manif *Manifest) error {
default:
return fmt.Errorf("stream %q: invalid kind %q", s.Name, s.Kind)
}

for idx, input := range s.Inputs {
if err := input.parse(); err != nil {
return fmt.Errorf("module %q: invalid input [%d]: %w", s.Name, idx, err)
Expand All @@ -105,27 +106,29 @@ func handleUseModules(pkg *pbsubstreams.Package, manif *Manifest) error {
}

for _, manifestModule := range manif.Modules {
if manifestModule.Use != "" {
usedModule, found := packageModulesMapping[manifestModule.Use]
if !found {
return fmt.Errorf("module %q: use module %q not found", manifestModule.Name, manifestModule.Use)
}
moduleWithUse := packageModulesMapping[manifestModule.Name]
if manifestModule.Use == "" {
continue
}

if err := checkEqualInputs(moduleWithUse, usedModule, manifestModule, packageModulesMapping); err != nil {
return fmt.Errorf("checking inputs for module %q: %w", manifestModule.Name, err)
}
usedModule, found := packageModulesMapping[manifestModule.Use]
if !found {
return fmt.Errorf("module %q: use module %q not found", manifestModule.Name, manifestModule.Use)
}
moduleWithUse := packageModulesMapping[manifestModule.Name]

moduleWithUse.BinaryIndex = usedModule.BinaryIndex
moduleWithUse.BinaryEntrypoint = usedModule.BinaryEntrypoint
if err := checkEqualInputs(moduleWithUse, usedModule, manifestModule, packageModulesMapping); err != nil {
return fmt.Errorf("checking inputs for module %q: %w", manifestModule.Name, err)
}

if moduleWithUse.InitialBlock == 0 {
moduleWithUse.InitialBlock = usedModule.InitialBlock
}
moduleWithUse.BinaryIndex = usedModule.BinaryIndex
moduleWithUse.BinaryEntrypoint = usedModule.BinaryEntrypoint

moduleWithUse.Output = usedModule.Output
moduleWithUse.Kind = usedModule.Kind
if moduleWithUse.InitialBlock == 0 {
moduleWithUse.InitialBlock = usedModule.InitialBlock
}

moduleWithUse.Output = usedModule.Output
moduleWithUse.Kind = usedModule.Kind
}
return nil
}
Expand All @@ -140,6 +143,7 @@ func checkEqualInputs(moduleWithUse, usedModule *pbsubstreams.Module, manifestMo
if input.GetParams().Value != usedModuleInput.GetParams().Value {
return fmt.Errorf("module %q: input %q has different value than the used module %q: input %q", manifestModuleWithUse.Name, input.String(), manifestModuleWithUse.Use, usedModuleInput.String())
}
continue
}
if input.GetSource() != nil {
if usedModuleInput.GetSource() == nil {
Expand All @@ -148,6 +152,7 @@ func checkEqualInputs(moduleWithUse, usedModule *pbsubstreams.Module, manifestMo
if input.GetSource().Type != usedModuleInput.GetSource().Type {
return fmt.Errorf("module %q: input %q has different source than the used module %q: input %q", manifestModuleWithUse.Name, input.String(), manifestModuleWithUse.Use, usedModuleInput.String())
}
continue
}
if input.GetStore() != nil {
if usedModuleInput.GetStore() == nil {
Expand All @@ -158,10 +163,21 @@ func checkEqualInputs(moduleWithUse, usedModule *pbsubstreams.Module, manifestMo
}

inputStoreModuleName := input.GetStore().ModuleName
_, found := packageModulesMapping[inputStoreModuleName]
if !found {
return fmt.Errorf("module %q: input %q store module %q not found", manifestModuleWithUse.Name, input.String(), inputStoreModuleName)
}

usedModuleStoreMapModuleName := usedModuleInput.GetStore().ModuleName
_, found = packageModulesMapping[usedModuleStoreMapModuleName]
if !found {
return fmt.Errorf("module %q: input %q store module %q not found", manifestModuleWithUse.Name, usedModuleInput.String(), usedModuleStoreMapModuleName)
}

if packageModulesMapping[inputStoreModuleName].Output.Type != packageModulesMapping[usedModuleStoreMapModuleName].Output.Type {
return fmt.Errorf("module %q: input %q has different output than the used module %q: input %q", manifestModuleWithUse.Name, input.String(), manifestModuleWithUse.Use, usedModuleInput.String())
}
continue

}
if input.GetMap() != nil {
Expand All @@ -170,10 +186,21 @@ func checkEqualInputs(moduleWithUse, usedModule *pbsubstreams.Module, manifestMo
}

inputMapModuleName := input.GetMap().ModuleName
_, found := packageModulesMapping[inputMapModuleName]
if !found {
return fmt.Errorf("module %q: input %q map module %q not found", manifestModuleWithUse.Name, input.String(), inputMapModuleName)
}

usedModuleInputMapModuleName := usedModuleInput.GetMap().ModuleName
_, found = packageModulesMapping[usedModuleInputMapModuleName]
if !found {
return fmt.Errorf("module %q: input %q map module %q not found", manifestModuleWithUse.Name, usedModuleInput.String(), usedModuleInputMapModuleName)
}

if packageModulesMapping[inputMapModuleName].Output.Type != packageModulesMapping[usedModuleInputMapModuleName].Output.Type {
return fmt.Errorf("module %q: input %q has different output than the used module %q: input %q", manifestModuleWithUse.Name, input.String(), manifestModuleWithUse.Use, usedModuleInput.String())
}
continue
}
}
return nil
Expand Down

0 comments on commit d6bc223

Please sign in to comment.