No description
Find a file
Mai-Lapyst 1848ce8363
All checks were successful
/ release (push) Successful in 5s
Update: 1.5.7: fix arrows when using multiple line labels
2025-11-17 03:25:55 +01:00
.forgejo/workflows Switch to forgejo actions 2024-07-10 06:21:26 +02:00
example Adding license header to example as well 2023-08-23 09:24:33 +02:00
src Update: 1.5.7: fix arrows when using multiple line labels 2025-11-17 03:25:55 +01:00
.gitignore Update .gitignore 2023-05-25 09:59:08 +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 Support utf-8 content 2024-07-10 06:15:44 +02:00
sample.tao First commit 2023-05-25 09:34:54 +02:00

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
  • Support utf16 & utf32

Thanks

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