-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathGeosExceptions.cpp
More file actions
77 lines (66 loc) · 2.62 KB
/
GeosExceptions.cpp
File metadata and controls
77 lines (66 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2024 TotalEnergies
* Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2023-2024 Chevron
* Copyright (c) 2019- GEOS/GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/
/**
* @file GeosExceptions.cpp
*/
#include "common/logger/GeosExceptions.hpp"
namespace geos
{
thread_local std::ostringstream Exception::m_formattingOSS;
void Exception::prepareWhat( DiagnosticMsg & msg ) noexcept
{
m_formattingOSS.str( "" );
m_formattingOSS.clear();
ErrorLogger::formatMsgForLog( msg,
m_formattingOSS,
ErrorLogger::global().isSourceInfoEnabled( msg.m_type ) );
m_cachedWhat = m_formattingOSS.bad() ? "Exception formatting error!" : m_formattingOSS.str();
}
/**
* @brief Insert an exception message in another one.
* @param originalMsg original exception message (i.e. thrown from GEOS_THROW)
* @param msgToInsert message to insert at the top of the originalMsg
*/
std::string insertExMsg( std::string const & originalMsg, std::string const & msgToInsert )
{
std::string newMsg( originalMsg );
size_t insertPos = 0;
// for readability purposes, we try to insert the message after the "***** Rank N: " or after "***** " instead of at the top.
static string_view constexpr rankLogStart = "***** Rank ";
static string_view constexpr rankLogEnd = ": ";
static string_view constexpr simpleLogStart = "***** ";
if( ( insertPos = newMsg.find( rankLogStart ) ) != std::string::npos )
{
insertPos = newMsg.find( rankLogEnd, insertPos + rankLogStart.size() )
+ rankLogEnd.size();
}
else if( ( insertPos = newMsg.rfind( simpleLogStart ) ) != std::string::npos )
{
insertPos += simpleLogStart.size();
}
else
{
insertPos = 0;
}
newMsg.insert( insertPos, msgToInsert );
return newMsg;
}
InputError::InputError( std::exception const & subException, std::string const & msgToInsert ):
geos::Exception( insertExMsg( subException.what(), msgToInsert ) )
{}
SimulationError::SimulationError( std::exception const & subException, std::string const & msgToInsert ):
geos::Exception( insertExMsg( subException.what(), msgToInsert ) )
{}
}