<commit_before>package io.pivio;

import io.pivio.upload.Writer;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

@Service
public class Application implements CommandLineRunner {

    @Autowired
    Configuration configuration;

    @Autowired
    Collector collector;

    @Autowired
    Writer writer;

    @Autowired
    Logger log;


    /**
     * This is the main method called by Spring Boot when a class implements Sprint Boot CommandLineRunner.
     * This method is the start point of the client.
     *
     * @param args Arguments of the Spring Boot application.
     */
    @Override
    public void run(String[] args) {
        try {
            CommandLine commandLine = configuration.parseCommandLine(args);
            configuration.setParameter(commandLine);
            if (configuration.hasOption(Configuration.SWITCH_HELP)) {
                configuration.outputHelp();
            } else {
                if (configuration.hasOption(Configuration.SWITCH_YAML_DIR)) {
                    List<Map<String, Object>> files = collector.gatherMultipleFiles();
                    for (Map<String, Object> file : files) {
                        checkForIdElement(file);
                        writer.write(file);
                    }
                } else {
                    Map<String, Object> document = collector.gatherSingleFile();
                    checkForIdElement(document);
                    writer.write(document);
                }
            }

        } catch (MissingIdException missingId) {
            log.output(missingId.getMessage());
            System.exit(0);
        } catch (PivioFileNotFoundException | FileNotFoundException e) {
            log.output(e.getMessage());
            if (configuration.hasOption(Configuration.SWITCH_PIVIO_FILE_NOT_FOUND_EXIT0)) {
                System.exit(0);
            } else {
                System.exit(1);
            }
        } catch (ParseException e) {
            log.output("Could not parse the command line parameters. ");
            System.exit(1);
        }
    }

    void checkForIdElement(Map<String, Object> document) throws MissingIdException {
        if (!document.containsKey("id")) {
            StringBuilder content = new StringBuilder();
            document.keySet().forEach(key -> {
                content.append(document.get(key));
            });
            throw new IllegalArgumentException("You need to have an id element in your configuration. (" + content + ")");
        }
    }

}
<commit_msg>Throwing the right exception.<commit_after>package io.pivio;

import io.pivio.upload.Writer;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

@Service
public class Application implements CommandLineRunner {

    @Autowired
    Configuration configuration;

    @Autowired
    Collector collector;

    @Autowired
    Writer writer;

    @Autowired
    Logger log;


    /**
     * This is the main method called by Spring Boot when a class implements Sprint Boot CommandLineRunner.
     * This method is the start point of the client.
     *
     * @param args Arguments of the Spring Boot application.
     */
    @Override
    public void run(String[] args) {
        try {
            CommandLine commandLine = configuration.parseCommandLine(args);
            configuration.setParameter(commandLine);
            if (configuration.hasOption(Configuration.SWITCH_HELP)) {
                configuration.outputHelp();
            } else {
                if (configuration.hasOption(Configuration.SWITCH_YAML_DIR)) {
                    List<Map<String, Object>> files = collector.gatherMultipleFiles();
                    for (Map<String, Object> file : files) {
                        checkForIdElement(file);
                        writer.write(file);
                    }
                } else {
                    Map<String, Object> document = collector.gatherSingleFile();
                    checkForIdElement(document);
                    writer.write(document);
                }
            }

        } catch (MissingIdException missingId) {
            log.output(missingId.getMessage());
            System.exit(0);
        } catch (PivioFileNotFoundException | FileNotFoundException e) {
            log.output(e.getMessage());
            if (configuration.hasOption(Configuration.SWITCH_PIVIO_FILE_NOT_FOUND_EXIT0)) {
                System.exit(0);
            } else {
                System.exit(1);
            }
        } catch (ParseException e) {
            log.output("Could not parse the command line parameters. ");
            System.exit(1);
        }
    }

    void checkForIdElement(Map<String, Object> document) throws MissingIdException {
        if (!document.containsKey("id")) {
            StringBuilder content = new StringBuilder();
            document.keySet().forEach(key -> content.append(document.get(key)));
            throw new MissingIdException("You need to have an id element in your configuration. (" + content + ")");
        }
    }

}

{'fraction_non_alphanumeric': 0.09225817986769176, 'fraction_numerical': 0.0017879492222420883, 'mean_word_length': 2.133893557422969, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '398018', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1373, 'n_words': 319}