<commit_before>var data2xml = require('data2xml');
var data2xmlConvert = data2xml();

var toGPX = function(trackingResult, callback, name) {
	var i, len, trkpts = [], started;
	var name = name || 'Untitled';
	len = trackingResult.points.length
	
	if (len > 0) {
		started = trackingResult.points[0].time.toISOString();
	} else {
		started = new Date().toISOString()
	}
	
	for( i = 0; i < len; i++) {
		trkpts.push({
			ele : trackingResult.points[i].ele,
			time : trackingResult.points[i].time.toISOString(),
			_attr : {
				lat : trackingResult.points[i].lat,
				lon : trackingResult.points[i].lng
			}
		});
	}

	var obj = {
		trk : {
			name : name,
			time : started,
			trkseg : {
				trkpt : trkpts
			}
		},
		_attr : {
			'version' : '1.1',
			'creator' : 'gps-util - https://github.com/vanng822/gps-util',
			'xmlns:xsi' : 'http://www.w3.org/2001/XMLSchema-instance',
			'xmlns' : 'http://www.topografix.com/GPX/1/1',
			'xsi:schemaLocation' : 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd',
			'xmlns:gpxtpx' : 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1'
		}
	};
	
	callback(null, data2xmlConvert('gpx', obj));
};
var toTCX = function(trackingResult, callback, name) {
	var name = name || 'Untitled';
	throw new Error('Implement!');
};<commit_msg>data2xml can throw error so handle it<commit_after>var data2xml = require('data2xml');
var data2xmlConvert = data2xml();

var toGPX = function(trackingResult, callback, name) {
	var i, len, trkpts = [], started;
	var name = name || 'Untitled';
	len = trackingResult.points.length
	
	if (len > 0) {
		started = trackingResult.points[0].time.toISOString();
	} else {
		started = new Date().toISOString()
	}
	
	for( i = 0; i < len; i++) {
		trkpts.push({
			ele : trackingResult.points[i].ele,
			time : trackingResult.points[i].time.toISOString(),
			_attr : {
				lat : trackingResult.points[i].lat,
				lon : trackingResult.points[i].lng
			}
		});
	}

	var obj = {
		trk : {
			name : name,
			time : started,
			trkseg : {
				trkpt : trkpts
			}
		},
		_attr : {
			'version' : '1.1',
			'creator' : 'gps-util - https://github.com/vanng822/gps-util',
			'xmlns:xsi' : 'http://www.w3.org/2001/XMLSchema-instance',
			'xmlns' : 'http://www.topografix.com/GPX/1/1',
			'xsi:schemaLocation' : 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd',
			'xmlns:gpxtpx' : 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1'
		}
	};
	try {
		result = data2xmlConvert('gpx', obj);
	} catch(e) {
		return callback(e, null);
	}
	callback(null, result);
};
var toTCX = function(trackingResult, callback, name) {
	var name = name || 'Untitled';
	throw new Error('Implement!');
};
{'fraction_non_alphanumeric': 0.18349981502034776, 'fraction_numerical': 0.018867924528301886, 'mean_word_length': 3.403908794788274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 10, 'xml': 19}, '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': '2703899', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1062, 'n_words': 187}