Data Structures | Namespaces | Functions

Errata.h File Reference

Stacking error message handling. More...

#include <memory>
#include <string>
#include <iosfwd>
#include <deque>
#include "NumericType.h"
#include "IntrusivePtr.h"
Include dependency graph for Errata.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  ts::Errata
 Class to hold a stack of error messages (the "errata"). More...
class  ts::Errata::Sink
 Base class for erratum sink. More...
struct  ts::Errata::SinkFunctionWrapper
struct  ts::Errata::Message
 Storage for a single message. More...
struct  ts::Errata::Data
 This is the implementation class for Errata. More...
class  ts::Errata::iterator
 Forward iterator for Messages in an Errata. More...
class  ts::Errata::const_iterator
 Forward constant iterator for Messages in an Errata. More...
struct  ts::RvBase
 Helper class for Rv. More...
struct  ts::Rv< R >
 Return type for returning a value and status (errata). More...

Namespaces

namespace  ts
 

Apache Traffic Server commons.


Functions

std::ostream & ts::operator<< (std::ostream &os, Errata const &err)
template<typename R >
Rv< R > ts::MakeRv (R const &r, Errata const &s)
 Combine a function result and status in to an Rv.

Detailed Description

Stacking error message handling.

The problem addressed by this library is the ability to pass back detailed error messages from failures. It is hard to get good diagnostics because the specific failures and general context are located in very different stack frames. This library allows local functions to pass back local messages which can be easily augmented as the error travels up the stack frame.

This could be done with exceptions but

Each message on a stack contains text and a numeric identifier. The identifier value zero is reserved for messages that are not errors so that information can be passed back even in the success case.

The implementation takes the position that success is fast and failure is expensive. Therefore it is optimized for the success path, imposing very little overhead. On the other hand, if an error occurs and is handled, that is generally so expensive that optimizations are pointless (although, of course, one should not be gratuitiously expensive).

The library also provides the Rv ("return value") template to make returning values and status easier. This template allows a function to return a value and status pair with minimal changes. The pair acts like the value type in most situations, while providing access to the status.

Each instance of an erratum is a wrapper class that emulates value semantics (copy on write). This means passing even large message stacks is inexpensive, involving only a pointer copy and reference counter increment and decrement. A success value is represented by an internal NULL so it is even cheaper to copy.

To further ease use, the library has the ability to define sinks. A sink is a function that acts on an erratum when it becomes unreferenced. The indended use is to send the messages to an output log. This makes reporting errors to a log from even deeply nested functions easy while preserving the ability of the top level logic to control such logging.

License

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file Errata.h.