OpenNHP/opennhp · error

invalid --data-source-type, allowed values are online…

Error message

invalid --data-source-type, allowed values are online, offline and stream

What it means

CLI validation in the nhp-db main command's Before hook: when running in encrypt mode, the --data-source-type flag must be one of "online", "offline", or "stream" (checked with slices.Contains). Any other value aborts the command before execution.

Solutions

  1. Use exactly one of: online, offline, stream (lowercase).
  2. Fix typos in the invoking script/Makefile and drop surrounding whitespace/quotes.
  3. Omit --data-source-type entirely if you don't need to set it (empty value is allowed).
  4. Update automation to validate the value with a shell case statement before invoking the binary.

Example fix

// before
./nhp-db --mode encrypt --data-source-type Online

// after
./nhp-db --mode encrypt --data-source-type online
Defensive patterns

Strategy: validation

Validate before calling

valid := []string{"online", "offline", "stream"}
if !slices.Contains(valid, os.Getenv("DATA_SOURCE_TYPE")) {
    return fmt.Errorf("DATA_SOURCE_TYPE must be one of %v", valid)
}

Type guard

func isvalidDataSourceType(s string) bool { return s == "" || slices.Contains([]string{"online", "offline", "stream"}, s) }

Try / catch

if err := app.Run(os.Args); err != nil {
    if strings.Contains(err.Error(), "invalid --data-source-type") {
        fmt.Fprintln(os.Stderr, "usage: --data-source-type online|offline|stream")
        os.Exit(2)
    }
}

Prevention

When it happens

Trigger: Running `nhp-db main ... --mode encrypt --data-source-type <anything-else>`, e.g. a typo like "onine", capitalized "Online", or "batch".

Common situations: Copy-pasted flag value from docs/scripts with a typo; case sensitivity ("Online"); outdated scripts using a removed enum value; shell variable expanding empty-then-trimmed or unexpected value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at endpoints/db/main/main.go:53

		Usage: "create and run device process for NHP protocol",
		Flags: []cli.Flag{
			&cli.StringFlag{Name: "mode", Value: "none", Usage: "encrypt;decrypt"},
			&cli.StringFlag{Name: "source", Value: "", Usage: "source file to be encrypted, this is not required for streaming mode"},
			&cli.StringFlag{Name: "data-source-type", Value: "", Usage: "type of data source, the default value is online, supported values are online, offline and stream"},
			&cli.StringFlag{Name: "smart-policy", Value: "", Usage: "The wasm policy file"},
			&cli.StringFlag{Name: "metadata", Value: "", Usage: "metadata file"},
			&cli.StringFlag{Name: "output", Value: "", Usage: "Save path of the ztdo file or decrypted file"},
			&cli.StringFlag{Name: "access-url", Value: "", Usage: "ZTDO access url for online or offline mode or API url for streaming mode"},
			&cli.StringFlag{Name: "ztdo", Value: "", Usage: "path to the ztdo file"},
			&cli.StringFlag{Name: "ztdo-id", Value: "", Usage: "identifier of the ztdo file"},
			&cli.StringFlag{Name: "data-private-key", Value: "", Usage: "data private key with base64 format"},
			&cli.StringFlag{Name: "provider-public-key", Value: "", Usage: "provider public key with base64 format"},
		},
		Before: func(c *cli.Context) error {
			if c.String("mode") == "encrypt" {
				if c.String("data-source-type") != "" {
					if !slices.Contains([]string{"online", "offline", "stream"}, c.String("data-source-type")) {
						return fmt.Errorf("invalid --data-source-type, allowed values are online, offline and stream")
					}
				}

				if c.String("ztdo-id") != "" { // update ztdo
					if c.String("source") != "" || c.String("output") != "" || c.String("metadata") != "" || c.String("data-source-type") != "" {
						return fmt.Errorf("--source, --output, --data-source-type and --metadata are not allowed when --ztdo-id is specified")
					}
				} else { // create ztdo
					if c.String("data-source-type") != "stream" {
						if c.String("source") == "" {
							return fmt.Errorf("--source is required when --data-source-type is not stream and --ztdo-id is not specified")
						}
					} else {
						if c.String("access-url") == "" {
							return fmt.Errorf("--access-url is required when --data-source-type is stream")
						}
					}
				}

View on GitHub (pinned to 6e04ca5ff0)