 
 public extension BundleUtil {
     
-    public func file(_ filename: String?, ofType type: String?) throws -> Data {
+    public func file(_ filename: String?, ofType type: String?) -> Result<Data> {
         let path = try self.path(of: filename, ofType: type)
         guard let fileData = try? Data(contentsOf: URL(fileURLWithPath: path)) else {
-            throw MochaException.fileNotFoundException
+            return .failure(.fileNotFoundException)
         }
-        return fileData
+        return .success(fileData)
     }
 }
 


public extension BundleUtil {
    
    public func path(of filename: String?, ofType type: String?) throws -> String {
        guard let path = bundle.path(forResource: filename, ofType: type) else {
            throw MochaException.fileNotFoundException
        }
        return path
    }
    
    public func resourcePath(of filename: String) throws -> String {
        guard let resourcePath = bundle.resourcePath else {
            throw MochaException.fileNotFoundException
        }
        return resourcePath.appendingPathComponent(filename)
    }
}



public extension BundleUtil {
    
    public func read(_ filename: String?, ofType type: String?, withEncoding encoding: String.Encoding = .utf8) -> Result<String> {
        let path = self.path(of: filename, ofType: type)
        return path.flatMap { read(atPath: $0) }
    }
    
    public func read(atPath filePath: String,
                     withEncoding encoding: String.Encoding = .utf8) -> Result<String> {
        do {
            return try .success(String(contentsOfFile: filePath, encoding: encoding))
        } catch {
            return .failure(.genericException(message: ""))
        }
    }
}
