{"record":{"id":"c89eaa5e7e46e1e7","repo":"voormedia/rails-erd","slug":"saving-diagram-failed-output-directory-file-di","errorCode":null,"errorMessage":"Saving diagram failed!\nOutput directory '#{File.dirname(filename)}' does not exist.","messagePattern":"Saving diagram failed!\nOutput directory '#(.+?)' does not exist\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/rails_erd/diagram/graphviz.rb","lineNumber":216,"sourceCode":"        GRAPH_ATTRIBUTES.each { |attribute, value| graph[attribute] = value }\n        NODE_ATTRIBUTES.each  { |attribute, value| graph.node[attribute] = value }\n        EDGE_ATTRIBUTES.each  { |attribute, value| graph.edge[attribute] = value }\n\n        # Switch rank direction if we're creating a vertically oriented graph.\n        graph[:rankdir] = (options.orientation == \"vertical\") ? :LR : :TB\n\n        # Title of the graph itself.\n        graph[:label] = \"#{title}\\\\n\\\\n\" if title\n\n        # Style of splines\n        graph[:splines] = options.splines unless options.splines.nil?\n\n        # Setup notation options.\n        extend self.class.const_get(options.notation.to_s.capitalize.to_sym)\n      end\n\n      save do\n        raise \"Saving diagram failed!\\nOutput directory '#{File.dirname(filename)}' does not exist.\" unless File.directory?(File.dirname(filename))\n\n        begin\n          # GraphViz doesn't like spaces in the filename\n          graph.output(filetype => filename.gsub(/\\s/,\"_\"))\n          filename\n        rescue RuntimeError => e\n          raise \"Saving diagram failed!\\nGraphviz produced errors. Verify it \" +\n                  \"has support for filetype=#{options.filetype}, or use \" +\n                  \"filetype=dot.\\nOriginal error: #{e.message.split(\"\\n\").last}\"\n        rescue StandardError => e\n          raise \"Saving diagram failed!\\nVerify that Graphviz is installed \" +\n                  \"and in your path, or use filetype=dot.\"\n        end\n      end\n\n      each_entity do |entity, attributes|\n        if options[:cluster] && entity.namespace\n          cluster_name = \"cluster_#{entity.namespace}\"","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/voormedia/rails-erd/blob/dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165/lib/rails_erd/diagram/graphviz.rb#L198-L234","documentation":"Before rendering, the Graphviz save callback (graphviz.rb:215-216) verifies the directory part of the output path exists: filename resolves to options.filename + '.' + options.filetype (graphviz.rb:297-299, default 'ERD.pdf'), and unless File.directory?(File.dirname(filename)) it raises immediately. With the default filename 'ERD' the dirname is '.' and never fails; the error appears as soon as the filename option points into a directory that does not exist, because neither rails-erd nor ruby-graphviz creates intermediate directories.","triggerScenarios":"RailsERD::Diagram::Graphviz.create(filename: 'docs/ERD') when docs/ does not exist; erd config erd.filename = 'doc/diagrams/erd' with a missing path segment; rake erd filename=tmp/erd after tmp/ was cleaned. Any filetype (pdf/png/dot) triggers it -- the check runs before graph.output is ever called.","commonSituations":"Writing diagrams into doc/ or db/visual/ folders that are gitignored and absent on CI clean checkouts; renaming the output directory after the erd config was written; fresh clones on machines that never had the directory.","solutions":["Create the directory: mkdir -p docs (matching File.dirname of your configured filename)","Or point filename at an existing directory","Or create it programmatically before generation: require 'fileutils'; FileUtils.mkdir_p(File.dirname(path))"],"exampleFix":"# before\nRailsERD::Diagram::Graphviz.create(filename: 'docs/ERD')\n# => RuntimeError: Saving diagram failed! Output directory 'docs' does not exist.\n\n# after\nrequire 'fileutils'\nFileUtils.mkdir_p('docs')\nRailsERD::Diagram::Graphviz.create(filename: 'docs/ERD')","handlingStrategy":"validation","validationCode":"path = File.join('docs', 'ERD.pdf')\nrequire 'fileutils'\nFileUtils.mkdir_p(File.dirname(path))\nRailsERD::Diagram::Graphviz.create(filename: 'docs/ERD')","typeGuard":null,"tryCatchPattern":"begin\n  RailsERD::Diagram::Graphviz.create(filename: 'docs/ERD')\nrescue RuntimeError => e\n  raise unless e.message.include?('Output directory')\n  require 'fileutils'\n  FileUtils.mkdir_p('docs')\n  retry\nend","preventionTips":["mkdir_p the output directory before every generate call (e.g. in a rake prerequisite)","Keep empty output directories in version control with a .keep file","Never assume rails-erd creates parent directories - it only checks them"],"tags":["ruby","rails-erd","graphviz","filesystem","output-path","directory-missing"],"backgroundTag":"output-directory-not-found","analyzedSha":"dae6e52018c94ff6d3e3bb0fdbc2cb0c680ec165","analyzedAt":"2026-08-23T02:52:18.679Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}