<commit_before>//
//  ErrorHandler.swift
//  FireAlarm
//
//  Created by <NAME> on 11/22/16.
//  Copyright © 2016 NobodyNada. All rights reserved.
//

import Foundation

var errorRoom: ChatRoom?

func errorAsNSError(_ error: Error) -> NSError? {
	#if os(Linux)
		//this is the only way I could find to check if an arbitrary Error is an NSError that doesn't crash on Linux
		//it produces a warning "'is' test is always true"
		return error is AnyObject ? unsafeBitCast(error, to: NSError.self) : nil
	#else
		return type(of: error) == NSError.self ? error as NSError : nil
	#endif
}

func handleError(_ error: Error, _ context: String? = nil) {
	let contextStr: String
	let errorType: String
	let errorDetails: String
	
	#if os(Linux)
		if let e = errorAsNSError(error) {
			errorType = "NSError"
			let e = unsafeBitCast(errorAsAny, to: NSError.self)
			errorDetails = "\(e.domain) code \(e.code) \(e.userInfo)"
		} else {
			errorType = String(reflecting: type(of: error))
			errorDetails = String(describing: error)
		}
	#else
		errorType = String(reflecting: type(of: error))
		errorDetails = String(describing: error)
	#endif
	
	if context != nil {
		contextStr = " \(context!)"
	}
	else {
		contextStr = ""
	}
	
	let message1 = "    An error (\(errorType)) occured\(contextStr):"
	
	if let room = errorRoom {
		room.postMessage(message1 + "\n    " + errorDetails.replacingOccurrences(of: "\n", with: "\n    "))
	}
	else {
		print("\(message1)\n\(errorDetails)")
		exit(1)
	}
}
<commit_msg>fixed compile error on Linux<commit_after>//
//  ErrorHandler.swift
//  FireAlarm
//
//  Created by <NAME> on 11/22/16.
//  Copyright © 2016 NobodyNada. All rights reserved.
//

import Foundation

var errorRoom: ChatRoom?

func errorAsNSError(_ error: Error) -> NSError? {
	#if os(Linux)
		//this is the only way I could find to check if an arbitrary Error is an NSError that doesn't crash on Linux
		//it produces a warning "'is' test is always true"
		return error is AnyObject ? unsafeBitCast(error, to: NSError.self) : nil
	#else
		return type(of: error) == NSError.self ? error as NSError : nil
	#endif
}

func handleError(_ error: Error, _ context: String? = nil) {
	let contextStr: String
	let errorType: String
	let errorDetails: String
	
	#if os(Linux)
		if let e = errorAsNSError(error) {
			errorType = "NSError"
			errorDetails = "\(e.domain) code \(e.code) \(e.userInfo)"
		} else {
			errorType = String(reflecting: type(of: error))
			errorDetails = String(describing: error)
		}
	#else
		errorType = String(reflecting: type(of: error))
		errorDetails = String(describing: error)
	#endif
	
	if context != nil {
		contextStr = " \(context!)"
	}
	else {
		contextStr = ""
	}
	
	let message1 = "    An error (\(errorType)) occured\(contextStr):"
	
	if let room = errorRoom {
		room.postMessage(message1 + "\n    " + errorDetails.replacingOccurrences(of: "\n", with: "\n    "))
	}
	else {
		print("\(message1)\n\(errorDetails)")
		exit(1)
	}
}

{'fraction_non_alphanumeric': 0.1342372881355932, 'fraction_numerical': 0.009491525423728813, 'mean_word_length': 3.450980392156863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4123146', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1015, 'n_words': 305}