{"record":{"id":"e358f5e3609bbec7","repo":"AdguardTeam/AdGuardHome","slug":"getting-current-directory-w","errorCode":null,"errorMessage":"getting current directory: %w","messagePattern":"getting current directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/home/service.go","lineNumber":99,"sourceCode":"\tp.logger.InfoContext(p.ctx, \"stopping: waiting for cleanup\")\n\n\taghos.SendShutdownSignal(p.signals)\n\n\t// Wait for other goroutines to complete their job.\n\t<-p.done\n\n\treturn nil\n}\n\n// handleRun runs p.\nfunc (p *program) handleRun(\n\tctx context.Context,\n\tbaseLogger *slog.Logger,\n\topts options,\n) (err error) {\n\tpwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting current directory: %w\", err)\n\t}\n\n\targs := optsToArgs(opts)\n\tbaseLogger.DebugContext(ctx, \"using\", \"args\", args)\n\n\tsvcConfig := &service.Config{\n\t\tName:             serviceName,\n\t\tDisplayName:      serviceDisplayName,\n\t\tDescription:      serviceDescription,\n\t\tWorkingDirectory: pwd,\n\t\tArguments:        args,\n\t}\n\tossvc.ConfigureServiceOptions(svcConfig, p.clock.Now(), version.Full())\n\n\ts, err := service.New(p, svcConfig)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initializing service: %w\", err)\n\t}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/home/service.go#L81-L117","documentation":"handleRun failed to obtain the current working directory with os.Getwd before building the service configuration. On Unix this fails when the process's cwd has been deleted or is unreadable.","triggerScenarios":"Running the 'service run' control action from a directory that was removed after the shell/process started, or in containers where the workdir was deleted or replaced.","commonSituations":"Starting AdGuard Home from a temp/build directory that gets cleaned up, or container setups where the working directory is an overlay that vanished.","solutions":["cd into a stable directory (e.g. /var/lib/adguardhome) before running the service action","Restart the shell/process if its cwd was deleted","In containers, set a persistent WORKDIR in the image"],"exampleFix":"# before\ncd /tmp/build-123 && ./AdGuardHome -s run\n\n# after\ncd /var/lib/adguardhome && ./AdGuardHome -s run","handlingStrategy":"validation","validationCode":"if pwd, err := os.Getwd(); err != nil {\n    os.Chdir(\"/var/lib/adguardhome\") // recover to a stable cwd\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Launch services from persistent directories","Set WORKDIR explicitly in containers and unit files"],"tags":["go","filesystem","service","cwd","os-getwd"],"backgroundTag":"working-directory-unavailable","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}