• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #68

19 Mar 2025 04:27PM UTC coverage: 27.092% (-0.02%) from 27.114%
#68

push

travis-ci

web-flow
add default terminate handler (#90)

This allows error handling in the scheduler to be simplified and
simplifies debugging. The auto-generated GDB wrapper scripts are updated
to break on this handler

0 of 31 new or added lines in 2 files covered. (0.0%)

5 existing lines in 2 files now uncovered.

2597 of 9586 relevant lines covered (27.09%)

4264.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main.cpp
1
/*************************************************************************\
2
 * AdapterRemoval - cleaning next-generation sequencing reads            *
3
 *                                                                       *
4
 * Copyright (C) 2011 by Stinus Lindgreen - stinus@binf.ku.dk            *
5
 * Copyright (C) 2014 by Mikkel Schubert - mikkelsch@gmail.com           *
6
 *                                                                       *
7
 * This program is free software: you can redistribute it and/or modify  *
8
 * it under the terms of the GNU General Public License as published by  *
9
 * the Free Software Foundation, either version 3 of the License, or     *
10
 * (at your option) any later version.                                   *
11
 *                                                                       *
12
 * This program is distributed in the hope that it will be useful,       *
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 * GNU General Public License for more details.                          *
16
 *                                                                       *
17
 * You should have received a copy of the GNU General Public License     *
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
19
\*************************************************************************/
20
#include "main.hpp"
21
#include "argparse.hpp"   // for parse_result, parse_result::error, parse_...
22
#include "debug.hpp"      // for AR_FAIL
23
#include "logging.hpp"    // for log_stream, error
24
#include "reports.hpp"    // for print_terminal_postamble, print_terminal_...
25
#include "userconfig.hpp" // for ar_command, userconfig, ar_command::demul...
26
#include <cstdlib>        // for abort, size_t
27
#include <exception>      // for set_terminate
28
#include <ios>            // for ios_base
29

30
namespace adapterremoval {
31

32
// See main_adapter_rm.cpp
33
int
34
remove_adapter_sequences(const userconfig& config);
35
// See main_adapter_id.cpp
36
int
37
identify_adapter_sequences(const userconfig& config);
38
// See main_demultiplex.cpp
39
int
40
demultiplex_sequences(const userconfig& config);
41
// See main_fastq_ro.cpp
42
int
43
fastq_report_only(const userconfig& config);
44
// See main_benchmark.cpp
45
int
46
benchmark(const userconfig& config);
47

48
[[noreturn]] void
49
terminate(const std::string& message)
×
50
{
51
  log::error()
×
52
    << message << "\n"
×
53
    << "This should not happen! Please file a bug-report at\n"
×
54
    << "    https://github.com/MikkelSchubert/adapterremoval/issues/new\n\n"
×
55
    << "Please specify the AdapterRemoval version used (" << VERSION << ")\n"
×
56
    << "and if possible describe the steps taken to reproduce this problem.";
×
57

58
  std::abort();
×
59
}
60

61
[[noreturn]] void
NEW
62
terminate_on_exception()
×
63
{
NEW
64
  try {
×
NEW
65
    std::exception_ptr eptr{ std::current_exception() };
×
66

NEW
67
    if (eptr) {
×
NEW
68
      std::rethrow_exception(eptr);
×
69
    } else {
NEW
70
      terminate("Aborted due to unknown error");
×
71
    }
NEW
72
  } catch (const std::exception& ex) {
×
NEW
73
    log::error()
×
NEW
74
      << ex.what()
×
75
      << "\nAdapterRemoval did not run to completion; do NOT make use of the "
NEW
76
         "resulting reads!";
×
NEW
77
  } catch (...) {
×
NEW
78
    terminate("Caught unknown exception type");
×
NEW
79
  }
×
80

NEW
81
  std::exit(1);
×
82
}
83

84
} // namespace adapterremoval
85

86
int
87
main(int argc, char* argv[])
×
88
{
89
  using namespace adapterremoval;
×
90

NEW
91
  std::set_terminate(&terminate_on_exception);
×
UNCOV
92
  std::ios_base::sync_with_stdio(false);
×
93

94
  userconfig config;
×
95

96
  const std::vector<std::string> argvec(argv, argv + argc);
×
97
  switch (config.parse_args(argvec)) {
×
98
    case argparse::parse_result::error:
99
      return 1;
100

101
    case argparse::parse_result::exit:
×
102
      // --version, --help, or similar used.
103
      return 0;
×
104

105
    case argparse::parse_result::ok:
×
106
      // Ok
107
      break;
×
108

109
    default:
×
110
      AR_FAIL("invalid argparse::parse_result");
×
111
  }
112

113
  print_terminal_preamble(config);
×
114

115
  auto returncode = 0;
×
116
  switch (config.run_type) {
×
117
    case ar_command::demultiplex_only:
×
118
    case ar_command::trim_adapters: {
×
119
      returncode = remove_adapter_sequences(config);
×
120
      break;
121
    }
122

123
    case ar_command::benchmark: {
×
124
      returncode = benchmark(config);
×
125
      break;
126
    }
127

128
    case ar_command::report_only: {
×
129
      returncode = identify_adapter_sequences(config);
×
130
      break;
131
    }
132

133
    default: {
×
134
      log::error() << "Unknown run-type: "
×
135
                   << static_cast<size_t>(config.run_type);
×
136
      return 1;
×
137
    }
138
  }
139

140
  print_terminal_postamble(config, returncode);
×
141

142
  return returncode;
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc