{"record":{"id":"d2331e6f11f478a2","repo":"OpenNHP/opennhp","slug":"registration-failed","errorCode":null,"errorMessage":"registration failed","messagePattern":"registration failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/agent/main/main.go","lineNumber":654,"sourceCode":"\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}\n\tfmt.Printf(\"  %sCipher scheme:%s    %s\\n\", colorYellow, colorReset, func() string {\n\t\tif cipherScheme == common.CIPHER_SCHEME_GMSM {","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/agent/main/main.go#L636-L672","documentation":"Companion to \"registration failed: %s\": when the server reports failure but the response carries no message text, runRegisterApp returns the bare \"registration failed\" error. It preserves deferred cleanup and non-zero exit while signaling that the server rejected the registration without explaining why.","triggerScenarios":"runRegisterApp receives a failed registration response where errMsgStr == \"\" — e.g. a generic NHP_ACK failure/timeout result with no detailed error field.","commonSituations":"Server rejecting on basic crypto/packet grounds before producing a plugin message; key mismatch causing a malformed exchange; older server version that doesn't populate the error message field; network interruption mid-registration.","solutions":["Enable debug logging on both agent and server to find the underlying rejection cause.","Verify the agent's keys match the server's peer table (PubKeyBase64 for the target cluster).","Check server logs around the registration time for plugin AuthWithNHP messages.","Retry registration; if intermittent, check UDP connectivity/firewall between agent and server (port 10581)."],"exampleFix":"// config.toml\n// before\nlogLevel = 2\n\n// after\nlogLevel = 0   # debug on both agent and server, then re-run registration","handlingStrategy":"retry","validationCode":"if resp == nil || (!resp.Success && resp.ErrMsg == \"\") {\n    log.Debug(\"registration rejected without detail; check server logs\")\n}","typeGuard":null,"tryCatchPattern":"if err := runRegisterApp(a, args); err != nil {\n    if err.Error() == \"registration failed\" {\n        log.Debug(\"no server detail; enable debug logs on server and retry\")\n    }\n    return err\n}","preventionTips":["Run agent and server at debug log level during first registration.","Verify peer PubKeyBase64 entries match on both sides.","Confirm UDP connectivity to the server's knock port before registering."],"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"}