Repository: ossrs/srs
File: trunk/src/app/srs_app_config.cpp (C++)

Code before:
        string exists_config_file;
        for (int i = 0; i < (int) try_config_files.size(); i++) {
            string try_config_file = try_config_files.at(i);
            if (srs_path_exists(try_config_file)) {
                exists_config_file = try_config_file;
                break;
            }
        }

        if (exists_config_file.empty()) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config file at %s", srs_join_vector_string(try_config_files, ", ").c_str());
        }

        if (config_file != exists_config_file) {
            srs_warn("user config %s does not exists, use %s instead", config_file.c_str(), exists_config_file.c_str());
            config_file = exists_config_file;
        }
    }

    // Parse the matched config file.
    if ((err = parse_file(config_file.c_str())) != srs_success) {
        return srs_error_wrap(err, "invalid config");
    }

    // transform config to compatible with previous style of config.
    if ((err = srs_config_transform_vhost(root)) != srs_success) {
        return srs_error_wrap(err, "transform");
    }

    if (test_conf) {
        // the parse_file never check the config,
        // we check it when user requires check config file.
        if ((err = check_config()) == srs_success) {
            srs_trace("config file is ok");
            exit(0);
        }

        srs_error("config file, %s", srs_error_desc(err).c_str());
        exit(srs_error_code(err));
    }

    ////////////////////////////////////////////////////////////////////////
    // check log name and level
    ////////////////////////////////////////////////////////////////////////
    if (true) {
        std::string log_filename = this->get_log_file();
        if (get_log_tank_file() && log_filename.empty()) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no log file");
        }
        if (get_log_tank_file()) {
            srs_trace("you can check log by: tail -n 30 -f %s", log_filename.c_str());

Review comment (suggestion):
When testing the configuration: if an error occurs here, then the previous result is to print the error message and exit.

Now this logic is not like that anymore. There are still problems with this modification.

`TRANS_BY_GPT3`

Code after:
        string exists_config_file;
        for (int i = 0; i < (int) try_config_files.size(); i++) {
            string try_config_file = try_config_files.at(i);
            if (srs_path_exists(try_config_file)) {
                exists_config_file = try_config_file;
                break;
            }
        }

        if (exists_config_file.empty()) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config file at %s", srs_join_vector_string(try_config_files, ", ").c_str());
        }

        if (config_file != exists_config_file) {
            srs_warn("user config %s does not exists, use %s instead", config_file.c_str(), exists_config_file.c_str());
            config_file = exists_config_file;
        }
    }

    // Parse the matched config file.
    err = parse_file(config_file.c_str());

    if (test_conf) {
        // the parse_file never check the config,
        // we check it when user requires check config file.
        if (err == srs_success && (err = srs_config_transform_vhost(root)) == srs_success) {
            if ((err = check_config()) == srs_success) {
                srs_trace("the config file %s syntax is ok", config_file.c_str());
                srs_trace("config file %s test is successful", config_file.c_str());
                exit(0);
            }
        }

        srs_trace("invalid config%s in %s", srs_error_summary(err).c_str(), config_file.c_str());
        srs_trace("config file %s test is failed", config_file.c_str());
        exit(srs_error_code(err));
    }

    if (err != srs_success) {
        return srs_error_wrap(err, "invalid config");
    }

    // transform config to compatible with previous style of config.
    if ((err = srs_config_transform_vhost(root)) != srs_success) {
        return srs_error_wrap(err, "transform");
    }

    ////////////////////////////////////////////////////////////////////////
    // check log name and level
    ////////////////////////////////////////////////////////////////////////
    if (true) {