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

openmc-dev / openmc / 33994779277

05 Sep 2026 10:02PM UTC coverage: 81.36% (+0.06%) from 81.301%
33994779277

Pull #4012

github

web-flow
Merge 88cb6833e into 33eaa7cf2
Pull Request #4012: Geometry debug function

18690 of 27173 branches covered (68.78%)

Branch coverage included in aggregate %.

89 of 102 new or added lines in 1 file covered. (87.25%)

2309 existing lines in 73 files now uncovered.

60586 of 70265 relevant lines covered (86.23%)

49880313.57 hits per line

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

84.0
/src/error.cpp
1
#include "openmc/error.h"
2

3
#include "openmc/message_passing.h"
4
#include "openmc/settings.h"
5

6
#if defined(__unix__) || defined(__unix) ||                                    \
7
  (defined(__APPLE__) && defined(__MACH__))
8
#include <unistd.h> // for isatty
9
#endif
10

11
#include <cstdlib> // for exit
12
#include <iomanip> // for setw
13
#include <iostream>
14

15
//==============================================================================
16
// Functions
17
//==============================================================================
18

19
namespace openmc {
20

21
namespace {
22

23
std::string error_message;
24

25
} // namespace
26

27
void set_errmsg(const char* message)
71 ✔
28
{
29
  error_message = message;
71 ✔
30
}
71 ✔
31

32
void set_errmsg(const std::string& message)
209 ✔
33
{
34
  error_message = message;
209 ✔
35
}
209 ✔
36

UNCOV
37
void set_errmsg(const std::stringstream& message)
×
38
{
UNCOV
39
  error_message = message.str();
×
UNCOV
40
}
×
41

42
const char* get_errmsg()
1,391,692 ✔
43
{
44
  return error_message.c_str();
1,391,692 ✔
45
}
46

47
extern "C" const char* openmc_get_err_msg()
1,391,665 ✔
48
{
49
  return get_errmsg();
1,391,665 ✔
50
}
51

52
#ifdef OPENMC_MPI
53
void abort_mpi(int code)
54
{
55
  MPI_Abort(mpi::intracomm, code);
56
}
57
#endif
58

59
void output(const std::string& message, std::ostream& out, int indent)
224,493 ✔
60
{
61
  // Set line wrapping and indentation
62
  int line_wrap = 80;
224,493 ✔
63

64
  // Determine length of message
65
  int length = message.size();
224,493 ✔
66

67
  int i_start = 0;
224,493 ✔
68
  int line_len = line_wrap - indent + 1;
224,493 ✔
69
  while (i_start < length) {
234,982 !
70
    if (length - i_start < line_len) {
234,982 ✔
71
      // Remainder of message will fit on line
72
      out << message.substr(i_start) << std::endl;
224,493 ✔
73
      break;
224,493 ✔
74

75
    } else {
76
      // Determine last space in current line
77
      std::string s = message.substr(i_start, line_len);
10,489 ✔
78
      auto pos = s.find_last_of(' ');
10,489 ✔
79

80
      // Write up to last space, or whole line if no space is present
81
      out << s.substr(0, pos) << '\n' << std::setw(indent) << " ";
20,978 ✔
82

83
      // Advance starting position
84
      i_start += (pos == std::string::npos) ? line_len : pos + 1;
10,489 ✔
85
    }
10,489 ✔
86
  }
87
}
224,493 ✔
88

89
void warning(const std::string& message)
9,417 ✔
90
{
91
#ifdef _POSIX_VERSION
92
  // Make output yellow if user is in a terminal
93
  if (isatty(STDERR_FILENO)) {
9,417 !
94
    std::cerr << "\033[0;33m";
×
95
  }
96
#endif
97

98
  // Write warning
99
  std::cerr << " WARNING: ";
9,417 ✔
100
  output(message, std::cerr, 10);
9,417 ✔
101

102
#ifdef _POSIX_VERSION
103
  // Reset color for terminal
104
  if (isatty(STDERR_FILENO)) {
9,417 !
UNCOV
105
    std::cerr << "\033[0m";
×
106
  }
107
#endif
108
}
9,417 ✔
109

110
void write_message(const std::string& message, int level)
235,764 ✔
111
{
112
  // Only allow master to print to screen
113
  if (!mpi::master)
235,764 ✔
114
    return;
115

116
  if (level <= settings::verbosity) {
217,843 ✔
117
    std::cout << " ";
214,910 ✔
118
    output(message, std::cout, 1);
214,910 ✔
119
  }
120
}
121

122
void fatal_error(const std::string& message, int err)
166 ✔
123
{
124
#pragma omp critical(FatalError)
154 ✔
125
  {
166 ✔
126
#ifdef _POSIX_VERSION
127
    // Make output red if user is in a terminal
128
    if (isatty(STDERR_FILENO)) {
166 !
129
      std::cerr << "\033[0;31m";
×
130
    }
131
#endif
132

133
    // Write error message
134
    std::cerr << " ERROR: ";
166 ✔
135
    output(message, std::cerr, 8);
166 ✔
136

137
#ifdef _POSIX_VERSION
138
    // Reset color for terminal
139
    if (isatty(STDERR_FILENO)) {
166 !
UNCOV
140
      std::cerr << "\033[0m";
×
141
    }
142
#endif
143
  }
144

145
#ifdef OPENMC_MPI
146
  MPI_Abort(mpi::intracomm, err);
57 ✔
147
#endif
148

149
  // Abort the program
150
  std::exit(err);
109 ✔
151
}
152

153
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc