C++ header-only library for error reporting
Go to file
Mai Lapyst a2d1c4a643
bithero_agency/LapystOrg/lib-error-reporting-cpp/pipeline/head This commit looks good Details
Update v1.4.0
2023-11-26 20:15:45 +01:00
example Adding license header to example as well 2023-08-23 09:24:33 +02:00
src Update v1.4.0 2023-11-26 20:15:45 +01:00
.gitignore Update .gitignore 2023-05-25 09:59:08 +02:00
Jenkinsfile Update Jenkinsfile 2023-05-26 23:55:25 +02:00
LICENSE First commit 2023-05-25 09:34:54 +02:00
Nittofile First commit 2023-05-25 09:34:54 +02:00
readme.md Adding MessageBuilder 2023-05-25 09:58:01 +02:00
sample.tao First commit 2023-05-25 09:34:54 +02:00
test._rs First commit 2023-05-25 09:34:54 +02:00

readme.md

error-reporting-cpp

A header-only error-reporting libary for c++.

License

The code in this repository is licensed under AGPL-3.0-or-later; for more details see the LICENSE file in the repository.

Usage

using namespace ErrorReporting;

// create colors through an color generator (thanks to ariadne.rs)
auto colors = ColorGenerator();
auto a = colors.next();

// create an explicit color
auto out = Color::fixed(81);

auto r1 = std::make_unique<Report<StdStrSpan>>(ReportKind_Error);
(*r1)
    // sets the error-code
    .with_code("03")
    // sets the primary error message
    .with_message(Message("Incompatible types"))
    // adds an label (source-annotation) to the report
    .with_label(
        Label{
            // A span is a range inside a sourcefile
            StdStrSpan(
                "sample.tao",       // the source's id
                Position(2, 8, 25), // the starting position
                Position(2, 9, 25)  // the ending position

                // Note: positions consist of 3 parts:
                //  - line number; one-based
                //  - column number; one-based
                //  - line-offset: the byteoffset to the begin of the line; zero-based
            )
        }
            // Adds a message to the label with a colored in word "Nat"
            .with_message(Message("This is of type ").add_part("Nat", a))
            // Sets the arrow color of the label
            .with_color(a)
    )
    .with_label(
        Label{ StdStrSpan("sample.tao", Position(3, 8, 35), Position(3, 11, 35)) }
            // Using the MessageBuilder, building messages can be written in a much nicer syntax
            .with_message(MessageBuilder{} << "This is of type " << b << "Str")
            .with_color(b)
    );

// Creates a container for sources
auto files = StaticFiles<StdStrSpan::SourceId>{};
// adds a source from a std::istream via StreamSource
files.with_source("main.rs", new StreamSource(new std::ifstream("./test._rs")));

// Creates a renderer for terminals
auto renderer = TerminalRenderer<StdStrSpan::SourceId>(std::cerr, files);
// renders the report
renderer << r1;

For more, see the example directory.

TODOs

  • Correctly implement support for rendering 1+ multiline labels
  • Fix chain-calling interfaces so that the objects dont get destructed that often

Thanks

Thanks to ariadne.rs for a fantastic crate that inspired me to create this.