{"record":{"id":"84a2ac892d849776","repo":"presidentbeef/brakeman","slug":"comparison-file-doesn-t-exist","errorCode":null,"errorMessage":"Comparison file doesn't exist","messagePattern":"Comparison file doesn't exist","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/brakeman.rb","lineNumber":556,"sourceCode":"  end\n\n  def self.announce message\n    logger.announce message\n  end\n\n  def self.alert message\n    logger.alert message\n  end\n\n  def self.debug message\n    logger.debug message\n  end\n\n  # Compare JSON output from a previous scan and return the diff of the two scans\n  def self.compare options\n    require 'json'\n    require 'brakeman/differ'\n    raise ArgumentError.new(\"Comparison file doesn't exist\") unless File.exist? options[:previous_results_json]\n\n    begin\n      previous_results = JSON.parse(File.read(options[:previous_results_json]), :symbolize_names => true)[:warnings]\n    rescue JSON::ParserError\n      self.alert \"Error parsing comparison file: #{options[:previous_results_json]}\"\n      exit!\n    end\n\n    tracker = run(options)\n    new_report = JSON.parse(tracker.report.to_json, symbolize_names: true)\n\n    new_results = new_report[:warnings]\n    obsolete_ignored = tracker.unused_fingerprints\n\n    Brakeman::Differ.new(new_results, previous_results).diff.tap do |diff|\n      diff[:obsolete] = obsolete_ignored\n    end\n  end","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/presidentbeef/brakeman/blob/649e678d0a46bda0e7c35874fa7af5d16e19b4f1/lib/brakeman.rb#L538-L574","documentation":"Brakeman's comparison mode (CLI flag `--compare FILE`) re-runs a scan and diffs it against a previously saved JSON report. Before doing anything, `Brakeman.compare` checks `File.exist?(options[:previous_results_json])` and raises `ArgumentError` if the baseline file is not on disk. This is a pre-flight guard: the comparison is impossible without a prior JSON report.","triggerScenarios":"Running `brakeman --compare tmp/brakeman.json` (or programmatically `Brakeman.compare :previous_results_json => path`) when that path does not exist: the baseline was never generated with `-o`/`--output`, the relative path resolves from a different working directory, the filename has a typo, or a CI artifact from a previous job was not restored.","commonSituations":"CI pipelines that run `--compare` on the very first build (no baseline artifact yet); baseline saved with a different filename than the one passed to `--compare`; artifact uploaded to a job that isn't downloaded before the compare step; running brakeman from a subdirectory so a relative path like `tmp/brakeman.json` points elsewhere.","solutions":["Confirm the file actually exists at the exact path passed: `ls -l tmp/brakeman.json` from the same directory brakeman runs in.","If you have no baseline yet, generate one first: `brakeman -o tmp/brakeman.json`, then run `brakeman --compare tmp/brakeman.json`.","Use an absolute path (e.g. `--compare $PWD/tmp/brakeman.json`) or run brakeman from the directory the relative path is written against.","In CI, make the compare step conditional: restore the baseline artifact and only call `--compare` when it exists; otherwise run a normal scan that produces the baseline for the next run."],"exampleFix":"# before (first CI run, baseline does not exist yet)\nbrakeman --compare tmp/brakeman.json   # => ArgumentError: Comparison file doesn't exist\n\n# after (generate baseline, then compare)\nbrakeman -o tmp/brakeman.json\nbrakeman --compare tmp/brakeman.json","handlingStrategy":"validation","validationCode":"# Ruby, before invoking Brakeman.compare / `brakeman --compare`\nbaseline = Rails.root.join('tmp/brakeman.json')\nif File.exist?(baseline)\n  Brakeman.compare :previous_results_json => baseline.to_s, :app_path => Rails.root.to_s\nelse\n  warn 'No baseline report found; generating one now.'\n  Brakeman.run(:app_path => Rails.root.to_s, :output_files => [baseline.to_s])\nend","typeGuard":null,"tryCatchPattern":"begin\n  Brakeman.compare :previous_results_json => path, :app_path => app\nrescue ArgumentError => e\n  abort \"#{e.message} — run `brakeman -o #{path}` first to create the baseline.\"\nend","preventionTips":["Generate the baseline JSON in the same CI job or workspace step that later consumes it with --compare, so existence is guaranteed.","Use absolute paths for --compare to avoid working-directory mismatches between steps.","On first run in CI, detect the missing artifact (test -f) and fall back to a plain scan that also saves the baseline."],"tags":["brakeman","file-not-found","cli","comparison","json","argument-error"],"backgroundTag":"file-not-found","analyzedSha":"649e678d0a46bda0e7c35874fa7af5d16e19b4f1","analyzedAt":"2026-08-21T18:43:10.938Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}