<commit_before>var fs = require('fs');
var path = require('path');
var less = require('less');
var async = require('async');
var common = require('./common.js');

var lessSrcPath = process.argv[2];
var lessSrcName = process.argv[3];
var lessDestDir = process.argv[4];
var minify = process.argv[5] === 'true';
var logLevel = parseInt(process.argv[6]);

common.mkdirsIfNotExistSync(lessDestDir);
lessConvert(lessSrcPath, lessSrcName, [path.dirname(lessSrcPath)], path.join(lessDestDir, lessSrcName.replace(/\.less/, '.css')));

function lessConvert(filepath, filename, searchPaths, outputPath) {
  var lessString = fs.readFileSync(filepath, 'utf8');
  async.series([
    function(callback) {
      less.render(lessString,
        {
          paths: searchPaths,
          filename: filename,
          compress: minify
        },
        function (e, output) {
          if (e) {
            common.logE(logLevel, 'LESS: compilation failed: ' + e);
            callback(e, "render");
            return;
          }
          common.mkdirsIfNotExistSync(path.dirname(outputPath));
          fs.writeFile(outputPath, output.css, function(err) {
            if (err) {
              common.logE(logLevel, 'LESS: saving file failed: ' + err);
              callback(err, "render");
            } else {
              common.logI(logLevel, 'LESS: processed ' + filepath);
              callback(null, "render");
            }
          });
        });
    }
  ], function(err, results) {
    if (err) {
      process.exit(1);
    }
  });
}<commit_msg>Fix that errors from async func are not handled in LESS<commit_after>var fs = require('fs');
var path = require('path');
var less = require('less');
var async = require('async');
var common = require('./common.js');

var lessSrcPath = process.argv[2];
var lessSrcName = process.argv[3];
var lessDestDir = process.argv[4];
var minify = process.argv[5] === 'true';
var logLevel = parseInt(process.argv[6]);

// Calling exit from async function does not work,
// so hook exiting event and exit again.
var exitCode = 0;
process.on('exit', function() {
  process.reallyExit(exitCode);
});

common.mkdirsIfNotExistSync(lessDestDir);
lessConvert(lessSrcPath, lessSrcName, [path.dirname(lessSrcPath)], path.join(lessDestDir, lessSrcName.replace(/\.less/, '.css')));

function lessConvert(filepath, filename, searchPaths, outputPath) {
  var lessString = fs.readFileSync(filepath, 'utf8');
  async.series([
    function(callback) {
      less.render(lessString,
        {
          paths: searchPaths,
          filename: filename,
          compress: minify
        },
        function (e, output) {
          if (e) {
            common.logE(logLevel, 'LESS: compilation failed: ' + e);
            callback(e, "render");
            return;
          }
          common.mkdirsIfNotExistSync(path.dirname(outputPath));
          fs.writeFile(outputPath, output.css, function(err) {
            if (err) {
              common.logE(logLevel, 'LESS: saving file failed: ' + err);
              callback(err, "render");
            } else {
              callback(null, "render");
            }
          });
        });
    }
  ], function(err, results) {
    if (err) {
      exitCode = 1;
    } else {
      common.logI(logLevel, 'LESS: processed ' + filepath);
    }
  });
}
{'fraction_non_alphanumeric': 0.14639299728342892, 'fraction_numerical': 0.004527618472683369, 'mean_word_length': 2.5749730312837107, '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': '2116312', 'n_tokens_mistral': 1008, 'n_tokens_neox': 998, 'n_words': 223}