{"record":{"id":"79919ed8b655807d","repo":"projectdiscovery/katana","slug":"could-not-create-graph-file","errorCode":null,"errorMessage":"could not create graph file","messagePattern":"could not create graph file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/graph/graph.go","lineNumber":136,"sourceCode":"\tactionsSlice := make([]*types.Action, 0, len(shortestPath))\n\tfor _, path := range shortestPath {\n\t\tpageVertex, err := g.graph.Vertex(path)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"could not get vertex\")\n\t\t}\n\n\t\tif pageVertex.URL == \"about:blank\" || pageVertex.NavigationAction == nil {\n\t\t\tcontinue\n\t\t}\n\t\tactionsSlice = append(actionsSlice, pageVertex.NavigationAction)\n\t}\n\treturn actionsSlice, nil\n}\n\nfunc (g *CrawlGraph) DrawGraph(file string) error {\n\tf, err := os.Create(file)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"could not create graph file\")\n\t}\n\tdefer func() { _ = f.Close() }()\n\n\treturn draw.DOT(g.graph, f)\n}\n","sourceCodeStart":118,"sourceCodeEnd":142,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/graph/graph.go#L118-L142","documentation":"CrawlGraph.DrawGraph renders the crawl graph as a DOT file for debugging. This error wraps a failure of os.Create(file), meaning the output file could not be created — typically a bad path, missing directory, or permission problem. The graph is never rendered; the call fails immediately.","triggerScenarios":"Calling DrawGraph with a path whose parent directory does not exist, with an invalid filename (e.g. empty string, path separators in a filename component), or to a location the process lacks write permission for (e.g. read-only container filesystem).","commonSituations":"Enabling graph debugging in a container where /tmp or the working directory is read-only; typo in the debug output path; running as a non-root user writing to a root-owned directory.","solutions":["Create the parent directory first (os.MkdirAll(filepath.Dir(file), 0o755)) before calling DrawGraph.","Verify the process has write permission on the target path (ls -ld on the directory).","Use a writable location such as os.TempDir() or an explicitly configured debug output directory.","Check the file path for typos, empty strings, or invalid characters."],"exampleFix":"// before\nif err := crawlGraph.DrawGraph(\"debug/graph.dot\"); err != nil { ... }\n// after\n_ = os.MkdirAll(\"debug\", 0o755)\nif err := crawlGraph.DrawGraph(\"debug/graph.dot\"); err != nil { ... }","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(graphFile)\nif err := os.MkdirAll(dir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create graph output dir %s: %w\", dir, err)\n}\nif err := os.WriteFile(graphFile, nil, 0o644); err != nil {\n    return fmt.Errorf(\"graph output path not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go: wrap DrawGraph with directory creation\nif err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil { return err }\nif err := crawlGraph.DrawGraph(file); err != nil {\n    return fmt.Errorf(\"draw graph to %s: %w\", file, err)\n}","preventionTips":["Always MkdirAll the output directory before DrawGraph.","Configure graph output into a known-writable directory (os.TempDir() or config).","Check write permissions when running in containers or as a non-root user."],"tags":["filesystem","io","permissions"],"backgroundTag":"file-create-permission-denied","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}