<commit_before>
errors = require 'errors'

exports.$appRun = -> [
	'$window', 'config', 'rpc'
	($window, config, rpc) ->
	
		# Hang up the socket unless it's the local (Node.js) client.
		unless $window.navigator.userAgent.match /^Node\.js .*$/
			rpc.call 'hangup'

]

exports.$service = -> [
	'$injector', '$q', 'require', 'socket'
	($injector, $q, require, socket) ->
		
		service = {}
		
		notifications = null
		
		try

			$injector.invoke [
				'ui/notifications'
				(_notifications_) -> notifications = _notifications_
			]
		
		# It's fine if this fails. 
		catch error
		
		service.call = (route, data) ->
			
			deferred = $q.defer()
			
			socket.emit "rpc://#{route}", data, ({error, result}) ->
				
				if error?
					
					error = errors.unserialize errors.caught error
					
					notifications.add(
						class: 'alert-danger'
						text: errors.message error
					) if notifications?
					
					deferred.reject error
					
				else
					
					deferred.resolve result
				
			deferred.promise
		<commit_msg>RPC errors can properly implement 'caught'<commit_after>
errors = require 'errors'

exports.$appRun = -> [
	'$window', 'config', 'rpc'
	($window, config, rpc) ->
	
		# Hang up the socket unless it's the local (Node.js) client.
		unless $window.navigator.userAgent.match /^Node\.js .*$/
			rpc.call 'hangup'

]

exports.$service = -> [
	'$injector', '$q', 'require', 'socket'
	($injector, $q, require, socket) ->
		
		service = {}
		
		notifications = null
		
		try

			$injector.invoke [
				'ui/notifications'
				(_notifications_) -> notifications = _notifications_
			]
		
		# It's fine if this fails. 
		catch error
		
		service.call = (route, data) ->
			
			deferred = $q.defer()
			
			socket.emit "rpc://#{route}", data, ({error, result}) ->
				
				if error?
					
					error = errors.caught errors.unserialize error
					
					notifications.add(
						class: 'alert-danger'
						text: errors.message error
					) if notifications?
					
					deferred.reject error
					
				else
					
					deferred.resolve result
				
			deferred.promise
		
{'fraction_non_alphanumeric': 0.13962445835339432, 'fraction_numerical': 0.0, 'mean_word_length': 2.3624595469255665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1069940', 'n_tokens_mistral': 907, 'n_tokens_neox': 649, 'n_words': 167}