{"record":{"id":"e0218b91e88c9c7b","repo":"Freika/dawarich","slug":"data-file-not-found-in-archive-data-json","errorCode":null,"errorMessage":"Data file not found in archive: data.json","messagePattern":"Data file not found in archive: data\\.json","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/services/users/import_data/v1_handler.rb","lineNumber":42,"sourceCode":"#   \"places\": [...]\n# }\n\nclass Users::ImportData::V1Handler\n  STREAM_BATCH_SIZE = 5000\n  STREAMED_SECTIONS = %w[places visits points].freeze\n\n  def initialize(user, import_directory, import_stats)\n    @user = user\n    @import_directory = import_directory\n    @import_stats = import_stats\n    @expected_counts = nil\n  end\n\n  def process\n    Rails.logger.info \"Processing v1 format archive for user: #{user.email}\"\n\n    json_path = import_directory.join('data.json')\n    raise StandardError, I18n.t('services.users.import_data.v1_handler.data_file_missing') unless File.exist?(json_path)\n\n    initialize_stream_state\n\n    handler = ::JsonStreamHandler.new(self)\n    parser = Oj::Parser.new(:saj, handler: handler)\n\n    File.open(json_path, 'rb') do |io|\n      parser.load(io)\n    end\n\n    finalize_stream_processing\n  rescue Oj::ParseError => e\n    raise StandardError, I18n.t('services.users.import_data.v1_handler.invalid_json', message: e.message)\n  rescue IOError => e\n    raise StandardError, I18n.t('services.users.import_data.v1_handler.read_failed', message: e.message)\n  end\n\n  attr_reader :expected_counts","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/services/users/import_data/v1_handler.rb#L24-L60","documentation":"StandardError raised by Users::ImportData::V1Handler#process when data.json is absent from the extracted import directory. In the normal flow the v1 handler is only selected because detect_format_version saw data.json exist, so reaching this raise means the file vanished between detection and processing, the entry was skipped during extraction (name rejected by sanitize_zip_entry_name, or oversized), or the handler was invoked directly with the wrong directory.","triggerScenarios":"Console/test invocation of V1Handler with a directory lacking data.json; a zip whose data.json entry has a name that gets sanitized to nil (contains '..' or is absolute); the tmp/import_* working directory being cleaned mid-run.","commonSituations":"Development against the handler in isolation, archives crafted with unusual entry names, or tmp-cleanup jobs racing a long import.","solutions":["Verify the extraction directory actually contains data.json (Dir.children of the tmp/import_* dir) before processing","Inspect the zip (unzip -l) and confirm an entry named exactly data.json at the root","Run the import end-to-end through Users::ImportData#import instead of the handler directly","Ensure nothing prunes Rails tmp/ while user-data imports run"],"exampleFix":"# before: invoking the handler directly against an arbitrary directory\nUsers::ImportData::V1Handler.new(user, Pathname.new('tmp/extracted'), stats).process\n\n# after: go through the orchestrator, which detects format and extracts first\nUsers::ImportData.new(user, 'path/to/export.zip').import","handlingStrategy":"validation","validationCode":"json_path = import_directory.join('data.json')\nraise ArgumentError, 'data.json missing from extraction directory' unless File.exist?(json_path)","typeGuard":"def v1_importable?(import_directory)\n  File.file?(import_directory.join('data.json'))\nend","tryCatchPattern":"begin\n  Users::ImportData::V1Handler.new(user, dir, stats).process\nrescue StandardError => e\n  # message distinguishes missing-file vs invalid-json vs read-failure\n  Rails.logger.error(\"v1 import failed: #{e.message}\")\n  raise\nend","preventionTips":["Always drive the handler through Users::ImportData#import so extraction and detection share one directory","Never invoke V1Handler against an arbitrary path in production code","Keep tmp cleanup jobs away from import directories during imports"],"tags":["import","export","missing-file","v1-handler","user-data-restore"],"backgroundTag":"missing-data-file","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}