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

openmc-dev / openmc / 15618759193

12 Jun 2025 06:59PM UTC coverage: 85.165% (+0.007%) from 85.158%
15618759193

Pull #3436

github

web-flow
Merge f2964f7dc into 6c9c69628
Pull Request #3436: Allowing chain_file to be chain object to save reloading time

18 of 22 new or added lines in 4 files covered. (81.82%)

374 existing lines in 7 files now uncovered.

52385 of 61510 relevant lines covered (85.17%)

36774825.05 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)
111,207✔
49
{
50
  // Set line wrapping and indentation
51
  int line_wrap = 80;
111,207✔
52

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

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

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

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

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

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

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

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

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

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

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

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

134
#ifdef OPENMC_MPI
135
  MPI_Abort(mpi::intracomm, err);
74✔
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

© 2025 Coveralls, Inc