OpenNHP/opennhp · error

AuthServiceId is required

Error message

AuthServiceId is required

What it means

runRegisterApp performs an interactive app registration flow. The AuthServiceId (asp-id) prompt is mandatory; if the user submits an empty line (just Enter), the command prints a colored error and returns "AuthServiceId is required" so main() exits non-zero instead of registering an app without an identity.

Solutions

  1. Enter the AuthServiceId exactly as configured in resource.toml when prompted.
  2. Pipe the value if automating: `echo "my-asp-id" | nhp-agent register ...` (ensure stdin stays open for later prompts).
  3. Check resource.toml [[Resources]] entries for the valid asp-id values first.
  4. If non-interactive use is needed, add/pass a --asp-id flag instead of relying on the prompt.

Example fix

// before (non-interactive shell)
nhp-agent register < /dev/null   # empty asp-id

// after
printf 'my-app-id\n' | nhp-agent register
Defensive patterns

Strategy: validation

Validate before calling

aspId := strings.TrimSpace(promptedValue)
if aspId == "" {
    return fmt.Errorf("AuthServiceId is required")
}

Try / catch

if err := runRegisterApp(...); err != nil {
    fmt.Fprintf(os.Stderr, "register: %v\n", err)
    os.Exit(1)
}

Prevention

When it happens

Trigger: Interactive `register` command reaches the asp-id prompt and the user presses Enter without typing a value; stdin is EOF/closed so the read yields an empty string rather than a read error.

Common situations: Running the command from a script or CI with piped/closed stdin; user not knowing the asp-id registered in resource.toml; accidentally skipping the prompt.

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/c4defa4d0f9c233b. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/agent/main/main.go:480

	// asp-id: default to the first resource entry's AuthServiceId if available,
	// falling back to "example" for the standard demo deployment.
	defaultAspId := "example"
	if aspId == "" {
		if kt := a.FirstKnockTarget(); kt != nil && kt.AuthServiceId != "" {
			defaultAspId = kt.AuthServiceId
		}
	}
	if aspId == "" {
		val, readErr := promptInput(reader, "AuthServiceId (asp-id)", defaultAspId)
		if readErr != nil {
			fmt.Printf("\n  %s❌ Failed to read input:%s %v\n\n", colorYellow, colorReset, readErr)
			return readErr
		}
		aspId = strings.TrimSpace(val)
		if aspId == "" {
			fmt.Printf("\n  %s❌ AuthServiceId is required%s\n\n", colorYellow, colorReset)
			return fmt.Errorf("AuthServiceId is required")
		}
	}

	// res-id: default from the matching resource.toml entry for this asp-id,
	// falling back to "demo" for the standard demo deployment.
	defaultResId := "demo"
	if resId == "" {
		if kt := a.FindKnockTargetByAspId(aspId); kt != nil && kt.ResourceId != "" {
			defaultResId = kt.ResourceId
		}
	}
	if resId == "" {
		val, readErr := promptInput(reader, "ResourceId (res-id)", defaultResId)
		if readErr != nil {
			fmt.Printf("\n  %s❌ Failed to read input:%s %v\n\n", colorYellow, colorReset, readErr)
			return readErr
		}
		resId = strings.TrimSpace(val)

View on GitHub (pinned to 6e04ca5ff0)