OpenNHP/opennhp · error

aspId or resId is empty

Error message

aspId or resId is empty

What it means

AddResource requires both ResourceData.AuthServiceId (which ASP owns it) and ResourceData.ResourceId (its key in the ASP's ResourceGroups map). If either string is empty the resource cannot be filed, so it is rejected up front.

Solutions

  1. Populate both AuthServiceId and ResourceId on the ResourceData before the call
  2. Fix the resource.toml entry so both fields are present and non-empty
  3. Validate the ResourceData at construction time and skip/defect log invalid entries

Example fix

// before
srv.AddResource(&common.ResourceData{AuthServiceId: "asp-1"})
// after
srv.AddResource(&common.ResourceData{AuthServiceId: "asp-1", ResourceId: "web-portal"})
Defensive patterns

Strategy: validation

Validate before calling

func validResource(r *common.ResourceData) bool {
    return r != nil && r.AuthServiceId != "" && r.ResourceId != ""
}
if !validResource(res) { return errors.New("resource needs AuthServiceId and ResourceId") }
err := srv.AddResource(res)

Type guard

func resourceIsComplete(r *common.ResourceData) bool { return r != nil && len(r.AuthServiceId) > 0 && len(r.ResourceId) > 0 }

Try / catch

if err := srv.AddResource(res); err != nil {
    return fmt.Errorf("AddResource(asp=%q, res=%q): %w", res.AuthServiceId, res.ResourceId, err)
}

Prevention

When it happens

Trigger: Calling UdpServer.AddResource with a *common.ResourceData where AuthServiceId == "" or ResourceId == "".

Common situations: TOML resource entries missing the resourceId key; plugins building ResourceData from partial JSON where one field is absent; renaming a resource field in config and not updating the loader mapping.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/370e4d21431e4d3c. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/server/udpserver.go:1110

	s.authServiceMap[aspData.AuthSvcId] = aspData
	s.authServiceMapMutex.Unlock()

	if len(aspData.PluginPath) > 0 {
		h := plugins.ReadPluginHandler(aspData.PluginPath)
		if h != nil {
			err := s.LoadPlugin(aspData.AuthSvcId, h)
			if err != nil {
				return err
			}
		}
	}

	return nil
}

func (s *UdpServer) AddResource(res *common.ResourceData) error {
	if len(res.AuthServiceId) == 0 || len(res.ResourceId) == 0 {
		return fmt.Errorf("aspId or resId is empty")
	}

	s.authServiceMapMutex.Lock()
	aspData, found := s.authServiceMap[res.AuthServiceId]
	if !found {
		s.authServiceMapMutex.Unlock()
		return fmt.Errorf("aspId not found")
	}
	aspData.ResourceGroups[res.ResourceId] = res
	s.authServiceMapMutex.Unlock()

	return nil
}

func (s *UdpServer) ValidatePlugin(h plugins.PluginHandler) bool {
	// placeholder to validate plugin file
	// err = checkSignature(s.Signature())
	// if err != nil {

View on GitHub (pinned to 6e04ca5ff0)