{"record":{"id":"3310dce4b9845b81","repo":"paperclipai/paperclip","slug":"refusing-to-replace-service-definition-not-owned-b","errorCode":null,"errorMessage":"Refusing to replace service definition not owned by the current user: ${filePath}.","messagePattern":"Refusing to replace service definition not owned by the current user: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/services/service-manager.ts","lineNumber":148,"sourceCode":"  <key>ExitTimeOut</key><integer>300</integer>\n  <key>StandardOutPath</key><string>${escapeXml(input.stdoutPath)}</string>\n  <key>StandardErrorPath</key><string>${escapeXml(input.stderrPath)}</string>\n</dict>\n</plist>\n`;\n}\n\nasync function writeIfChanged(filePath: string, contents: string): Promise<boolean> {\n  const directoryPath = path.dirname(filePath);\n  await fs.mkdir(directoryPath, { recursive: true, mode: 0o700 });\n  const directoryStat = await fs.lstat(directoryPath);\n  if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) throw new Error(`Refusing to write service definition through unsafe directory ${directoryPath}.`);\n  const currentUid = process.getuid?.();\n  if (currentUid !== undefined && directoryStat.uid !== currentUid) throw new Error(`Refusing to write service definition in directory not owned by the current user: ${directoryPath}.`);\n  try {\n    const stat = await fs.lstat(filePath);\n    if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink > 1) throw new Error(`Refusing to replace unsafe service definition ${filePath}.`);\n    if (currentUid !== undefined && stat.uid !== currentUid) throw new Error(`Refusing to replace service definition not owned by the current user: ${filePath}.`);\n    if (await fs.readFile(filePath, \"utf8\") === contents) return false;\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n  const temporaryPath = path.join(directoryPath, `.${path.basename(filePath)}.tmp-${process.pid}-${Date.now()}`);\n  try {\n    await fs.writeFile(temporaryPath, contents, { encoding: \"utf8\", mode: 0o644, flag: \"wx\" });\n    await fs.rename(temporaryPath, filePath);\n  } finally {\n    await fs.rm(temporaryPath, { force: true });\n  }\n  return true;\n}\n\nexport class SystemdServiceManager implements ServiceManager {\n  readonly platform = \"systemd\" as const;\n  readonly serviceName: string;\n  readonly definitionPath: string;","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/cli/src/services/service-manager.ts#L130-L166","documentation":"The existing service definition file is not owned by the current user, so the guard refuses to modify definitions belonging to another user or the system.","triggerScenarios":"Thrown at cli/src/services/service-manager.ts:148 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Change ownership of ${filePath} to the current user, or remove it and let the manager recreate it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}