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

openmc-dev / openmc / 21686031975

04 Feb 2026 07:50PM UTC coverage: 81.024% (-0.7%) from 81.763%
21686031975

Pull #3755

github

web-flow
Merge 27d6053a4 into b41e22f68
Pull Request #3755: Warn users that tally heating score with photon bin but without electron and positron bins.

16378 of 22828 branches covered (71.75%)

Branch coverage included in aggregate %.

22 of 23 new or added lines in 1 file covered. (95.65%)

862 existing lines in 51 files now uncovered.

54491 of 64639 relevant lines covered (84.3%)

8259986.93 hits per line

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

80.6
/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
// Global variables / constants
17
//==============================================================================
18

19
// Error codes
20
int OPENMC_E_UNASSIGNED {-1};
21
int OPENMC_E_ALLOCATE {-2};
22
int OPENMC_E_OUT_OF_BOUNDS {-3};
23
int OPENMC_E_INVALID_SIZE {-4};
24
int OPENMC_E_INVALID_ARGUMENT {-5};
25
int OPENMC_E_INVALID_TYPE {-6};
26
int OPENMC_E_INVALID_ID {-7};
27
int OPENMC_E_GEOMETRY {-8};
28
int OPENMC_E_DATA {-9};
29
int OPENMC_E_PHYSICS {-10};
30
int OPENMC_E_WARNING {1};
31

32
// Error message
33
char openmc_err_msg[256];
34

35
//==============================================================================
36
// Functions
37
//==============================================================================
38

39
namespace openmc {
40

41
#ifdef OPENMC_MPI
UNCOV
42
void abort_mpi(int code)
×
43
{
UNCOV
44
  MPI_Abort(mpi::intracomm, code);
×
UNCOV
45
}
×
46
#endif
47

48
void output(const std::string& message, std::ostream& out, int indent)
13,538✔
49
{
50
  // Set line wrapping and indentation
51
  int line_wrap = 80;
13,538✔
52

53
  // Determine length of message
54
  int length = message.size();
13,538✔
55

56
  int i_start = 0;
13,538✔
57
  int line_len = line_wrap - indent + 1;
13,538✔
58
  while (i_start < length) {
14,368!
59
    if (length - i_start < line_len) {
14,368✔
60
      // Remainder of message will fit on line
61
      out << message.substr(i_start) << std::endl;
13,538✔
62
      break;
13,538✔
63

64
    } else {
65
      // Determine last space in current line
66
      std::string s = message.substr(i_start, line_len);
830✔
67
      auto pos = s.find_last_of(' ');
830✔
68

69
      // Write up to last space, or whole line if no space is present
70
      out << s.substr(0, pos) << '\n' << std::setw(indent) << " ";
830✔
71

72
      // Advance starting position
73
      i_start += (pos == std::string::npos) ? line_len : pos + 1;
830✔
74
    }
830✔
75
  }
76
}
13,538✔
77

78
void warning(const std::string& message)
766✔
79
{
80
#ifdef _POSIX_VERSION
81
  // Make output yellow if user is in a terminal
82
  if (isatty(STDERR_FILENO)) {
766!
83
    std::cerr << "\033[0;33m";
×
84
  }
85
#endif
86

87
  // Write warning
88
  std::cerr << " WARNING: ";
766✔
89
  output(message, std::cerr, 10);
766✔
90

91
#ifdef _POSIX_VERSION
92
  // Reset color for terminal
93
  if (isatty(STDERR_FILENO)) {
766!
94
    std::cerr << "\033[0m";
×
95
  }
96
#endif
97
}
766✔
98

99
void write_message(const std::string& message, int level)
16,899✔
100
{
101
  // Only allow master to print to screen
102
  if (!mpi::master)
16,899✔
103
    return;
3,954✔
104

105
  if (level <= settings::verbosity) {
12,945✔
106
    std::cout << " ";
12,755✔
107
    output(message, std::cout, 1);
12,755✔
108
  }
109
}
110

111
void fatal_error(const std::string& message, int err)
17✔
112
{
113
#pragma omp critical(FatalError)
114
  {
115
#ifdef _POSIX_VERSION
116
    // Make output red if user is in a terminal
117
    if (isatty(STDERR_FILENO)) {
17!
118
      std::cerr << "\033[0;31m";
×
119
    }
120
#endif
121

122
    // Write error message
123
    std::cerr << " ERROR: ";
17✔
124
    output(message, std::cerr, 8);
17✔
125

126
#ifdef _POSIX_VERSION
127
    // Reset color for terminal
128
    if (isatty(STDERR_FILENO)) {
17!
129
      std::cerr << "\033[0m";
×
130
    }
131
#endif
132
  }
133

134
#ifdef OPENMC_MPI
135
  MPI_Abort(mpi::intracomm, err);
17✔
136
#endif
137

138
  // Abort the program
UNCOV
139
  std::exit(err);
×
140
}
141

142
} // namespace openmc
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