Error.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 04 Error Management */
10
11#include "squid.h"
12#include "base/IoManip.h"
13#include "debug/Stream.h"
14#include "error/Error.h"
15
16void
17Error::update(const err_type recentCategory)
18{
19 if (recentCategory == ERR_NONE)
20 return; // no category given
21
22 if (category == recentCategory)
23 return; // no new category given
24
25 if (category != ERR_NONE) {
26 debugs(4, 5, "ignoring: " << errorTypeName(recentCategory) << "; keeping " << *this);
27 return; // the category given earlier has won
28 }
29
30 category = recentCategory;
31 debugs(4, 3, "new: " << errorTypeName(category));
32}
33
34void
36{
37 if (!recentDetail)
38 return; // no new detail given
39
40 // an error can only have a few details so linear search is faster than indexing
41 for (const auto &oldDetail: details) {
42 if (recentDetail->equals(*oldDetail))
43 return; // the given detail is already present
44 }
45
46 details.push_back(recentDetail);
47 debugs(4, 3, "new: " << recentDetail);
48}
49
50void
51Error::update(const Error &recent)
52{
53 // checking category and detail separately may cause inconsistency, but
54 // may result in more details available if they only become available later
55 update(recent.category);
56 for (const auto &recentDetail: recent.details)
57 update(recentDetail);
58}
59
60void
61Error::update(const err_type recentCategory, const ErrorDetail::Pointer &recentDetail)
62{
63 // Optimization: Do not simply call update(Error(...)) here because that
64 // would require allocating and freeing heap memory for storing the detail.
65 update(recentCategory);
66 update(recentDetail);
67}
68
69std::ostream &
70operator <<(std::ostream &os, const ErrorDetails &details)
71{
72 os << AsList(details).delimitedBy("+");
73 return os;
74}
75
76std::ostream &
77operator <<(std::ostream &os, const Error &error)
78{
79 os << errorTypeName(error.category);
80 os << AsList(error.details).prefixedBy("/").delimitedBy("+");
81 return os;
82}
83
std::ostream & operator<<(std::ostream &os, const ErrorDetails &details)
Definition: Error.cc:70
std::vector< ErrorDetailPointer, PoolingAllocator< ErrorDetailPointer > > ErrorDetails
zero or more details of a single error
Definition: Error.h:20
const char * errorTypeName(err_type err)
Definition: Error.h:77
void error(char *format,...)
std::ostream manipulator to print containers as flat lists
Definition: IoManip.h:107
auto & prefixedBy(const char *const p)
a c-string to print before the first item (if any). Caller must ensure lifetime.
Definition: IoManip.h:112
auto & delimitedBy(const char *const d)
a c-string to print between consecutive items (if any). Caller must ensure lifetime.
Definition: IoManip.h:115
bool equals(const ErrorDetail &other) const
Definition: Detail.h:44
a transaction problem
Definition: Error.h:27
ErrorDetails details
Definition: Error.h:60
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:55
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:51
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
err_type
Definition: forward.h:14
@ ERR_NONE
Definition: forward.h:15

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors