{"record":{"id":"c0dbff86e472190f","repo":"netbirdio/netbird","slug":"read-service-params-s-w","errorCode":null,"errorMessage":"read service params %s: %w","messagePattern":"read service params (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/cmd/service_params.go","lineNumber":54,"sourceCode":"\tServiceEnvVars        map[string]string `json:\"service_env_vars,omitempty\"`\n}\n\n// serviceParamsPath returns the path to the service params file.\nfunc serviceParamsPath() string {\n\treturn filepath.Join(configs.StateDir, serviceParamsFile)\n}\n\n// loadServiceParams reads saved service parameters from disk.\n// Returns nil with no error if the file does not exist.\nfunc loadServiceParams() (*serviceParams, error) {\n\tpath := serviceParamsPath()\n\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, nil //nolint:nilnil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"read service params %s: %w\", path, err)\n\t}\n\n\tvar params serviceParams\n\tif err := json.Unmarshal(data, &params); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse service params %s: %w\", path, err)\n\t}\n\n\treturn &params, nil\n}\n\n// saveServiceParams writes current service parameters to disk atomically\n// with restricted permissions.\nfunc saveServiceParams(params *serviceParams) error {\n\tpath := serviceParamsPath()\n\tif err := util.WriteJsonWithRestrictedPermission(context.Background(), path, params); err != nil {\n\t\treturn fmt.Errorf(\"save service params: %w\", err)\n\t}\n\treturn nil","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/service_params.go#L36-L72","documentation":"loadServiceParams could not read <stateDir>/service.json. A missing file is fine (returns nil), so this is a genuine read failure: permissions on the file or directory, or the path not being a readable regular file.","triggerScenarios":"Running the CLI as an unprivileged user against a root-owned service.json under /var/lib/netbird (or C:\\ProgramData\\NetBird); a read-only mount; the path replaced by a directory or symlink loop.","commonSituations":"Inspecting or uninstalling a root-installed service from a normal user shell; hardened hosts with restrictive state directories.","solutions":["Run the command elevated (sudo or administrator)","Check ownership and mode: ls -l /var/lib/netbird/service.json","Fix with chown/chmod if the file should be user-accessible","As a last resort remove the file (defaults are re-derived on next install) after saving a copy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"path := serviceParamsPath()\nif info, err := os.Stat(path); err == nil {\n\tif info.IsDir() {\n\t\treturn fmt.Errorf(\"%s is a directory\", path)\n\t}\n\tif info.Mode().Perm()&0o400 == 0 {\n\t\treturn fmt.Errorf(\"no read permission on %s; run elevated\", path)\n\t}\n}","typeGuard":null,"tryCatchPattern":"data, err := os.ReadFile(path)\nif err != nil {\n\tif os.IsNotExist(err) {\n\t\treturn nil, nil\n\t}\n\treturn fmt.Errorf(\"read service params %s: %w\", path, err)\n}","preventionTips":["Run service commands with the same privileges that installed the service","Monitor ownership of the state directory after restores or migrations"],"tags":["service","state","file-permissions","go"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}