       try
         lang_json = JSON.parse(fs.readFileSync(file_path))
       catch error
-        rollback()
-
         throw new Meteor.Error 500, "Failed to build unified languages files. Invalid JSON in language file: `#{file_path}' of package #{package_map.name}",
           {file_path: file_path, error: error}
 
       if not _.isObject lang_json
-        rollback()
-
         throw new Meteor.Error 500, "Failed to build unified languages files. The JSON in language file: `#{file_path}' of package #{package_map.name} is not an object.",
           {file_path: file_path}
 

    _.each dialects, (dialect) ->
      base_language = (dialect.split "-")[0]
      if not (base_language of languages_files)
        rollback()
        throw new Meteor.Error 500, "Package #{package_map.name} has no language file for the base language (#{base_language}) of the dialect (#{dialect})"

    if supported_languages

      unified_languages_files[lang] += JSON.stringify lang_json

  for lang of unified_languages_files
    unified_languages_files[lang] += "}"

  # Add empty JSONs for supported languages we find no translation files for
  unified_languages_files = _.extend(
    _.object(_.map(supported_languages, (lang) -> [lang, "{}"])),
    unified_languages_files
  )

  log "Done generating unified languages files"
  return unified_languages_files

addUnifiedFilesAsFsFiles = (unified_languages_files, lang_files_path=default_build_files_path) ->
  log "Writing unified files directory to FS: #{lang_files_path}"

  lang_files_path = removeFileTrailingSeparator lang_files_path
  lang_files_backup_path = "#{lang_files_path}~"

  getLangFilePath = (lang) ->
    lang_files_path + path.sep + lang + ".json"

  # A rollback procedure to use on failure
  rollback = ->
    log "Build failed, rolling back `#{lang_files_path}'"
    wrench.rmdirSyncRecursive lang_files_path
    try
      fs.renameSync lang_files_backup_path, lang_files_path
    catch error

  # Remove old backup
  try
    wrench.rmdirSyncRecursive lang_files_backup_path
    log "Old languages files backup #{lang_files_backup_path} removed"
  catch error

  # Create a backup for current lang_files_path
  try
    fs.renameSync lang_files_path, lang_files_backup_path
    log "[IMPORTANT] unified languages files folder #{lang_files_path} already exists. Backing it up"
    log "[IMPORTANT] to #{lang_files_backup_path}. If you need to, save the backup before building your"
    log "[IMPORTANT] project again - otherwise you'll lose it."
  catch error

  # Create the new languages files dir
  try
    wrench.mkdirSyncRecursive lang_files_path, 0o744 # 0744 - owner: rwx, rest: r
  catch error
    rollback()

    throw new Meteor.Error 500, "Can't create folder `#{lang_files_path}'",
      {error: error}

  for lang of unified_languages_files
    if unified_languages_files[lang] == "{}"
      continue

    lang_file_path = getLangFilePath lang

    try
      fs.writeFileSync lang_file_path, unified_languages_files[lang], {mode: 0o644}
