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

openmc-dev / openmc / 15593141567

11 Jun 2025 06:49PM UTC coverage: 85.168% (+0.01%) from 85.158%
15593141567

Pull #3423

github

web-flow
Merge 8d67d5464 into 2eeba8999
Pull Request #3423: Fix raytrace infinite loop.

5 of 5 new or added lines in 1 file covered. (100.0%)

362 existing lines in 7 files now uncovered.

52396 of 61521 relevant lines covered (85.17%)

36622826.42 hits per line

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

89.74
/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
42
void abort_mpi(int code)
43
{
44
  MPI_Abort(mpi::intracomm, code);
45
}
46
#endif
47

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

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

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

64
    } else {
65
      // Determine last space in current line
66
      std::string s = message.substr(i_start, line_len);
8,093✔
67
      auto pos = s.find_last_of(' ');
8,093✔
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) << " ";
8,093✔
71

72
      // Advance starting position
73
      i_start += (pos == std::string::npos) ? line_len : pos + 1;
8,093✔
74
    }
8,093✔
75
  }
76
}
110,495✔
77

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

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

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

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

105
  if (level <= settings::verbosity) {
104,654✔
106
    std::cout << " ";
102,366✔
107
    output(message, std::cout, 1);
102,366✔
108
  }
109
}
110

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

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

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

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

138
  // Abort the program
139
  std::exit(err);
91✔
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