{"record":{"id":"07119098e697b846","repo":"OpenNHP/opennhp","slug":"invalid-data-source-type-allowed-values-are-onl","errorCode":null,"errorMessage":"invalid --data-source-type, allowed values are online, offline and stream","messagePattern":"invalid --data-source-type, allowed values are online, offline and stream","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/db/main/main.go","lineNumber":53,"sourceCode":"\t\tUsage: \"create and run device process for NHP protocol\",\n\t\tFlags: []cli.Flag{\n\t\t\t&cli.StringFlag{Name: \"mode\", Value: \"none\", Usage: \"encrypt;decrypt\"},\n\t\t\t&cli.StringFlag{Name: \"source\", Value: \"\", Usage: \"source file to be encrypted, this is not required for streaming mode\"},\n\t\t\t&cli.StringFlag{Name: \"data-source-type\", Value: \"\", Usage: \"type of data source, the default value is online, supported values are online, offline and stream\"},\n\t\t\t&cli.StringFlag{Name: \"smart-policy\", Value: \"\", Usage: \"The wasm policy file\"},\n\t\t\t&cli.StringFlag{Name: \"metadata\", Value: \"\", Usage: \"metadata file\"},\n\t\t\t&cli.StringFlag{Name: \"output\", Value: \"\", Usage: \"Save path of the ztdo file or decrypted file\"},\n\t\t\t&cli.StringFlag{Name: \"access-url\", Value: \"\", Usage: \"ZTDO access url for online or offline mode or API url for streaming mode\"},\n\t\t\t&cli.StringFlag{Name: \"ztdo\", Value: \"\", Usage: \"path to the ztdo file\"},\n\t\t\t&cli.StringFlag{Name: \"ztdo-id\", Value: \"\", Usage: \"identifier of the ztdo file\"},\n\t\t\t&cli.StringFlag{Name: \"data-private-key\", Value: \"\", Usage: \"data private key with base64 format\"},\n\t\t\t&cli.StringFlag{Name: \"provider-public-key\", Value: \"\", Usage: \"provider public key with base64 format\"},\n\t\t},\n\t\tBefore: func(c *cli.Context) error {\n\t\t\tif c.String(\"mode\") == \"encrypt\" {\n\t\t\t\tif c.String(\"data-source-type\") != \"\" {\n\t\t\t\t\tif !slices.Contains([]string{\"online\", \"offline\", \"stream\"}, c.String(\"data-source-type\")) {\n\t\t\t\t\t\treturn fmt.Errorf(\"invalid --data-source-type, allowed values are online, offline and stream\")\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif c.String(\"ztdo-id\") != \"\" { // update ztdo\n\t\t\t\t\tif c.String(\"source\") != \"\" || c.String(\"output\") != \"\" || c.String(\"metadata\") != \"\" || c.String(\"data-source-type\") != \"\" {\n\t\t\t\t\t\treturn fmt.Errorf(\"--source, --output, --data-source-type and --metadata are not allowed when --ztdo-id is specified\")\n\t\t\t\t\t}\n\t\t\t\t} else { // create ztdo\n\t\t\t\t\tif c.String(\"data-source-type\") != \"stream\" {\n\t\t\t\t\t\tif c.String(\"source\") == \"\" {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"--source is required when --data-source-type is not stream and --ztdo-id is not specified\")\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif c.String(\"access-url\") == \"\" {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"--access-url is required when --data-source-type is stream\")\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/db/main/main.go#L35-L71","documentation":"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.","triggerScenarios":"Running `nhp-db main ... --mode encrypt --data-source-type <anything-else>`, e.g. a typo like \"onine\", capitalized \"Online\", or \"batch\".","commonSituations":"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.","solutions":["Use exactly one of: online, offline, stream (lowercase).","Fix typos in the invoking script/Makefile and drop surrounding whitespace/quotes.","Omit --data-source-type entirely if you don't need to set it (empty value is allowed).","Update automation to validate the value with a shell case statement before invoking the binary."],"exampleFix":"// before\n./nhp-db --mode encrypt --data-source-type Online\n\n// after\n./nhp-db --mode encrypt --data-source-type online","handlingStrategy":"validation","validationCode":"valid := []string{\"online\", \"offline\", \"stream\"}\nif !slices.Contains(valid, os.Getenv(\"DATA_SOURCE_TYPE\")) {\n    return fmt.Errorf(\"DATA_SOURCE_TYPE must be one of %v\", valid)\n}","typeGuard":"func isvalidDataSourceType(s string) bool { return s == \"\" || slices.Contains([]string{\"online\", \"offline\", \"stream\"}, s) }","tryCatchPattern":"if err := app.Run(os.Args); err != nil {\n    if strings.Contains(err.Error(), \"invalid --data-source-type\") {\n        fmt.Fprintln(os.Stderr, \"usage: --data-source-type online|offline|stream\")\n        os.Exit(2)\n    }\n}","preventionTips":["Quote and lowercase flag values in scripts; avoid manual retyping.","Add shell autocompletion or a wrapper that validates the enum before exec.","Keep the enum list documented next to the command in runbooks."],"tags":["cli","validation","enum","nhp-db"],"backgroundTag":"invalid-enum-value","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}