Repository: airbnb/lottie-ios
File: Sources/Public/Animation/AnimationPublic.swift (Swift)

Code before:
    animationCache: AnimationCacheProvider? = nil)
    -> Animation?
  {
    /// Create a cache key for the animation.
    let cacheKey = bundle.bundlePath + (subdirectory ?? "") + "/" + name

    /// Check cache for animation
    if
      let animationCache = animationCache,
      let animation = animationCache.animation(forKey: cacheKey)
    {
      /// If found, return the animation.
      return animation
    }

    do {
      /// Decode animation.
      guard let json = try bundle.getAnimationData(name, subdirectory: subdirectory) else {
        return nil
      }
      let animation = try JSONDecoder().decode(Animation.self, from: json)
      animationCache?.setAnimation(animation, forKey: cacheKey)
      return animation
    } catch {
      /// Decoding error.
      LottieLogger.shared.assertionFailure("Error when decoding animation \"\(name)\": \(error)")
      return nil
    }
  }

  /**
   Loads an animation from a specific filepath.
   - Parameter filepath: The absolute filepath of the animation to load. EG "/User/Me/starAnimation.json"
   - Parameter animationCache: A cache for holding loaded animations. Optional.

   - Returns: Deserialized `Animation`. Optional.
   */
  public static func filepath(
    _ filepath: String,
    animationCache: AnimationCacheProvider? = nil)
    -> Animation?
  {

    /// Check cache for animation
    if
      let animationCache = animationCache,
      let animation = animationCache.animation(forKey: filepath)
    {
      return animation
    }


Review comment (bug):
Wondering if you think this should be a `warn`? I could imagine a case where you want to recover from an invalid animation and not have it crash in debug e.g. if you're writing a lottie viewer app

Code after:
    animationCache: AnimationCacheProvider? = nil)
    -> Animation?
  {
    /// Create a cache key for the animation.
    let cacheKey = bundle.bundlePath + (subdirectory ?? "") + "/" + name

    /// Check cache for animation
    if
      let animationCache = animationCache,
      let animation = animationCache.animation(forKey: cacheKey)
    {
      /// If found, return the animation.
      return animation
    }

    do {
      /// Decode animation.
      guard let json = try bundle.getAnimationData(name, subdirectory: subdirectory) else {
        return nil
      }
      let animation = try JSONDecoder().decode(Animation.self, from: json)
      animationCache?.setAnimation(animation, forKey: cacheKey)
      return animation
    } catch {
      /// Decoding error.
      LottieLogger.shared.warn("Error when decoding animation \"\(name)\": \(error)")
      return nil
    }
  }

  /**
   Loads an animation from a specific filepath.
   - Parameter filepath: The absolute filepath of the animation to load. EG "/User/Me/starAnimation.json"
   - Parameter animationCache: A cache for holding loaded animations. Optional.

   - Returns: Deserialized `Animation`. Optional.
   */
  public static func filepath(
    _ filepath: String,
    animationCache: AnimationCacheProvider? = nil)
    -> Animation?
  {

    /// Check cache for animation
    if
      let animationCache = animationCache,
      let animation = animationCache.animation(forKey: filepath)
    {
      return animation
    }