{"record":{"id":"6f44de904fea4201","repo":"grafana/k6","slug":"failed-to-open-logfile-s-w","errorCode":null,"errorMessage":"failed to open logfile %s: %w","messagePattern":"failed to open logfile (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/log/file.go","lineNumber":104,"sourceCode":"\n// openFile opens logfile and initializes writers.\nfunc (h *fileHook) openFile(getCwd func() (string, error)) error {\n\tpath := h.path\n\tif !filepath.IsAbs(path) {\n\t\tcwd, err := getCwd()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"'%s' is a relative path but could not determine CWD: %w\", path, err)\n\t\t}\n\t\tpath = filepath.Join(cwd, path)\n\t}\n\n\tif _, err := h.fs.Stat(filepath.Dir(path)); errors.Is(err, fs.ErrNotExist) {\n\t\treturn fmt.Errorf(\"provided directory '%s' does not exist\", filepath.Dir(path))\n\t}\n\n\tfile, err := h.fs.OpenFile(path, syscall.O_WRONLY|syscall.O_APPEND|syscall.O_CREAT, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open logfile %s: %w\", path, err)\n\t}\n\n\th.w = file\n\th.bw = bufio.NewWriter(file)\n\n\treturn nil\n}\n\n// Listen waits for log lines to flush.\nfunc (h *fileHook) Listen(ctx context.Context) {\n\tticker := time.NewTicker(fileHookFlushInterval)\n\tdefer ticker.Stop()\n\n\tfor {\n\t\tselect {\n\t\tcase entry := <-h.loglines:\n\t\t\tif _, err := h.bw.Write(entry); err != nil {\n\t\t\t\th.fallbackLogger.WithError(err).Error(\"failed to write a log message to a logfile\")","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/log/file.go#L86-L122","documentation":"Raised in openFile when h.fs.OpenFile fails to open/create the log file with write+append+create flags (permissions, read-only fs, path is a directory, etc.). The underlying OS error is wrapped with %w. The at-fault input is the resolved log file path.","triggerScenarios":"Thrown at internal/log/file.go:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check write permissions on the file/directory and that the path is not an existing directory","Ensure the filesystem is writable (not read-only container fs or disk-full)","Run with a user that has access to the path, or choose a different log location","Read the wrapped OS error for the exact cause"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}