<commit_before>var express = require("express");
var bodyParser = require("body-parser");
var cp = require("child_process");
var async = require("async");

module.exports = function(config){

	var app = express();
	app.use(bodyParser.json({limit: '50mb'}));
	console.log("config:", config);	
	app.use(function(req, res){
		var type = req.get("X-GitHub-Event");
		if(type == "push"){
			console.log("push repo, branch:", req.body.repository.full_name, req.body.ref);
			async.map(config.events, function(event, callback){
				if(req.body.ref == "refs/heads/" + event.branch && req.body.repository.full_name == event.repo){
					console.log("executing:", event.script);
					var out = "executing: " + event.script;
					cp.execFile(event.script, function(err, stdout, stderr){
						if(err){
							console.error("child_process error:", err);
							callback(err);
						}
						out += ("\nstdout:\n" + stdout);
						out += ("\nstderr:\n" + stderr);
						callback(null, out);
					});	
				}else{
					callback(null, "");
				}
			}, function(err, out){
				if(out.length > 0){
					console.log("completed:", out);
					res.status(200).end(out.join("\n")); 
				}else{
					res.status(202).end();
				}
			});
			
		}else{
			res.status(202).end();
		}
	});

	app.listen(config.port || 8888); 
};

<commit_msg>fix bug with error handeling<commit_after>var express = require("express");
var bodyParser = require("body-parser");
var cp = require("child_process");
var async = require("async");

module.exports = function(config){

	var app = express();
	app.use(bodyParser.json({limit: '50mb'}));
	console.log("config:", config);	
	app.use(function(req, res){
		var type = req.get("X-GitHub-Event");
		if(type == "push"){
			console.log("push repo, branch:", req.body.repository.full_name, req.body.ref);
			async.map(config.events, function(event, callback){
				if(req.body.ref == "refs/heads/" + event.branch && req.body.repository.full_name == event.repo){
					console.log("executing:", event.script);
					var out = "executing: " + event.script;
					cp.execFile(event.script, function(err, stdout, stderr){
						if(err){
							console.error("child_process error:", err);
							return callback(err);
						}
						out += ("\nstdout:\n" + stdout);
						out += ("\nstderr:\n" + stderr);
						callback(null, out);
					});	
				}else{
					callback(null, "");
				}
			}, function(err, out){
				if(out.length > 0){
					console.log("completed:", out);
					res.status(200).end(out.join("\n")); 
				}else{
					res.status(202).end();
				}
			});
			
		}else{
			res.status(202).end();
		}
	});

	app.listen(config.port || 8888); 
};


{'fraction_non_alphanumeric': 0.2028766086298259, 'fraction_numerical': 0.012112036336109008, 'mean_word_length': 3.2629032258064514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3411850', 'n_tokens_mistral': 1139, 'n_tokens_neox': 899, 'n_words': 163}