{"record":{"id":"9a8028256d8ab5e6","repo":"OpenNHP/opennhp","slug":"registration-failed-s","errorCode":null,"errorMessage":"registration failed: %s","messagePattern":"registration failed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/agent/main/main.go","lineNumber":652,"sourceCode":"\t\terrMsgStr := regErr.Error()\n\t\tif rakMsg != nil {\n\t\t\terrCode = rakMsg.ErrCode\n\t\t\tif rakMsg.ErrMsg != \"\" {\n\t\t\t\terrMsgStr = rakMsg.ErrMsg\n\t\t\t}\n\t\t}\n\t\tfmt.Println()\n\t\tfmt.Printf(\"  %s❌ Registration failed%s\\n\", colorYellow, colorReset)\n\t\tif errCode != \"\" {\n\t\t\tfmt.Printf(\"  %sError code:%s  %s\\n\", colorYellow, colorReset, errCode)\n\t\t}\n\t\tfmt.Printf(\"  %sError:%s        %s\\n\", colorYellow, colorReset, errMsgStr)\n\t\tfmt.Println()\n\t\t// Return the error instead of os.Exit so the deferred a.Stop()\n\t\t// (and any other cleanup) still runs. main() maps a non-nil error\n\t\t// to a non-zero exit code.\n\t\tif errMsgStr != \"\" {\n\t\t\treturn fmt.Errorf(\"registration failed: %s\", errMsgStr)\n\t\t}\n\t\treturn fmt.Errorf(\"registration failed\")\n\t}\n\n\t// Registration succeeded — print results.\n\tpubKey := a.PublicKeyBase64ByCipherScheme()\n\tprivKey := a.PrivateKeyBase64()\n\tfmt.Println()\n\tfmt.Printf(\"  %s✅ Registration successful!%s\\n\", colorGreen, colorReset)\n\tfmt.Println()\n\tfmt.Printf(\"  %sEmail (UserId):%s   %s\\n\", colorYellow, colorReset, email)\n\tfmt.Printf(\"  %sAuthServiceId:%s    %s\\n\", colorYellow, colorReset, aspId)\n\tif orgId != \"\" {\n\t\tfmt.Printf(\"  %sOrganization:%s     %s\\n\", colorYellow, colorReset, orgId)\n\t}\n\tif deviceId != \"\" {\n\t\tfmt.Printf(\"  %sDevice ID:%s        %s\\n\", colorYellow, colorReset, deviceId)\n\t}","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/agent/main/main.go#L634-L670","documentation":"After sending a registration knock, runRegisterApp inspects the server's response; when the server reports an error message, the command surfaces it as `registration failed: <server message>` so that deferred cleanup (a.Stop()) still runs and main() can exit non-zero. The embedded text is the rejection reason sent by the NHP server.","triggerScenarios":"Server registration response arrives with a non-empty errMsgStr (e.g. agent not approved, duplicate/unknown identity, policy rejection) during runRegisterApp.","commonSituations":"Agent public key not yet trusted by the server's plugin/ACL; asp-id not registered with the auth service provider; server-side policy rejecting the resource request; expired or rotated server keys after generate-nhp-keys.sh --regenerate.","solutions":["Read the embedded server message after the colon — it states the server-side rejection reason.","Register/approve the agent's public key with the server (registration list or plugin ACL).","Verify the asp-id/res-id exist on the server's resource/auth configuration.","If keys were rotated, redeploy peer tables so server and agent share current keys, then retry."],"exampleFix":"// server side: approve the agent identity before retrying\n// agent side: verify identity then re-run\nnhp-agent register --server nhp-server-cluster   # read exact server reason from error text","handlingStrategy":"try-catch","validationCode":"if resp.ErrMsg != \"\" {\n    return fmt.Errorf(\"registration failed: %s\", resp.ErrMsg)\n}","typeGuard":null,"tryCatchPattern":"if err := runRegisterApp(a, args); err != nil {\n    fmt.Fprintf(os.Stderr, \"register: %v\\n\", err) // deferred a.Stop() still runs\n    return err\n}","preventionTips":["Pre-approve the agent's public key on the server before registering.","Keep server-side asp-id/res-id registrations in sync with agent config.","Redeploy peer tables after any key rotation (generate-nhp-keys.sh)."],"tags":["registration","server-rejection","nhp","go"],"backgroundTag":"api-error-response","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"}