<commit_before>#!/usr/bin/env node

'use strict';

var Connection = require('ssh2');
var yaml = require('yamljs');

var targetName = process.argv[2];
var target;

function loadTarget(name) {
    return yaml.load(name + '.yaml');
}


if (!targetName) {
    console.error('Error: no target specified.');
    process.exit(1);
}

target = loadTarget(targetName);

var conn = new Connection();

conn.on('ready', function () {
    function handleNewStream(err, stream) {
        var stdin = process.stdin;

        if (err) {
            console.error(err);
            conn.end();
            process.exit(1);
            return;
        }

        stream.on('close', function () { conn.end(); });<commit_msg>Add better error reporting for failed target file loading<commit_after>#!/usr/bin/env node

'use strict';

var Connection = require('ssh2');
var yaml = require('yamljs');

var targetName = process.argv[2];
var target;

function loadTarget(name) {
    return yaml.load(name + '.yaml');
}


if (!targetName) {
    console.error('Error: no target specified.');
    process.exit(1);
}

try {
    target = loadTarget(targetName);
} catch (err) {
    if (err.code === 'ENOENT') {
        console.error('Error: could not find target file.\n' + err.message);
    } else {
        console.error('Error: could not parse target file.\n' + err.message);
        console.log(err.name);
    }

    process.exit(1);
}

var conn = new Connection();

conn.on('ready', function () {
    function handleNewStream(err, stream) {
        var stdin = process.stdin;

        if (err) {
            console.error(err);
            conn.end();
            process.exit(1);
            return;
        }

        stream.on('close', function () { conn.end(); });
{'fraction_non_alphanumeric': 0.15804597701149425, 'fraction_numerical': 0.005172413793103448, 'mean_word_length': 2.612033195020747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1715254', 'n_tokens_mistral': 546, 'n_tokens_neox': 532, 'n_words': 131}