• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14823373998

04 May 2025 05:03PM UTC coverage: 86.442% (+0.03%) from 86.409%
14823373998

push

github

SuperFola
fix: change the color of the function name inside runtime typechecking errors from blue to cyan to be easier to read inside dark terminals

0 of 1 new or added line in 1 file covered. (0.0%)

195 existing lines in 22 files now uncovered.

6835 of 7907 relevant lines covered (86.44%)

79668.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.29
/include/Ark/Exceptions.hpp
1
/**
2
 * @file Exceptions.hpp
3
 * @author Alexandre Plateau (lexplt.dev@gmail.com), Max (madstk1@pm.me)
4
 * @brief ArkScript homemade exceptions
5
 * @date 2020-10-27
6
 *
7
 * @copyright Copyright (c) 2020-2025
8
 *
9
 */
10

11
#ifndef INCLUDE_ARK_EXCEPTIONS_HPP
12
#define INCLUDE_ARK_EXCEPTIONS_HPP
13

14
#include <string>
15
#include <vector>
16
#include <stdexcept>
17
#include <optional>
18
#include <ostream>
19
#include <iostream>
20

21
#include <Ark/Compiler/AST/utf8_char.hpp>
22
#include <Ark/Platform.hpp>
23

24
namespace Ark
25
{
26
    namespace internal
27
    {
28
        class Node;
29
    }
30

31
    class ARK_API Error : public std::runtime_error
284✔
32
    {
33
    public:
34
        explicit Error(const std::string& message) :
284✔
35
            std::runtime_error(message)
284✔
36
        {}
568✔
37

UNCOV
38
        [[nodiscard]] virtual std::string details(bool colorize [[maybe_unused]]) const
×
39
        {
×
40
            return what();
×
41
        }
×
42
    };
43

44
    /**
45
     * @brief A type error triggered when types don't match
46
     *
47
     */
UNCOV
48
    class ARK_API TypeError final : public Error
×
49
    {
50
    public:
UNCOV
51
        explicit TypeError(const std::string& message) :
×
52
            Error(message)
×
53
        {}
×
54
    };
55

56
    /**
57
     * @brief An assertion error, only triggered from ArkScript code through (assert expr error-message)
58
     *
59
     */
UNCOV
60
    class ARK_API AssertionFailed final : public Error
×
61
    {
62
    public:
UNCOV
63
        explicit AssertionFailed(const std::string& message) :
×
64
            Error("AssertionFailed: " + message)
×
65
        {}
×
66
    };
67

68
    class ARK_API NestedError final : public Error
102✔
69
    {
70
    public:
71
        NestedError(const Error& e, const std::string& details) :
69✔
72
            Error("NestedError"),
69✔
73
            m_details(e.details(/* colorize= */ false))
69✔
74
        {
138✔
75
            if (!m_details.empty() && m_details.back() != '\n')
69✔
UNCOV
76
                m_details += '\n';
×
77
            m_details += "\n" + details;
69✔
78
        }
69✔
79

80
        NestedError(const std::exception& e, const std::string& details) :
33✔
81
            Error("NestedError"),
33✔
82
            m_details(e.what())
33✔
83
        {
66✔
84
            if (!m_details.empty() && m_details.back() != '\n')
33✔
85
                m_details += '\n';
10✔
86
            m_details += "\n" + details;
33✔
87
        }
33✔
88

89
        [[nodiscard]] const char* what() const noexcept override
102✔
90
        {
102✔
91
            return m_details.c_str();
102✔
92
        }
93

94
    private:
95
        std::string m_details;
96
    };
97

98
    /**
99
     * @brief CodeError thrown by the compiler (parser, macro processor, optimizer, and compiler itself)
100
     *
101
     */
102
    struct ARK_API CodeError final : Error
113✔
103
    {
104
        const std::string filename;
105
        const std::size_t line;
106
        const std::size_t col;
107
        const std::string expr;
108
        const std::optional<internal::utf8_char_t> symbol;
109

110
        CodeError(
113✔
111
            const std::string& what,
112
            std::string filename_,
113
            const std::size_t lineNum,
114
            const std::size_t column,
115
            std::string exp,
116
            const std::optional<internal::utf8_char_t> opt_sym = std::nullopt) :
117
            Error(what),
113✔
118
            filename(std::move(filename_)), line(lineNum), col(column), expr(std::move(exp)), symbol(opt_sym)
113✔
119
        {}
339✔
120
    };
121

122
    namespace Diagnostics
123
    {
124
        /**
125
         * @brief Helper to create a colorized context to report errors to the user
126
         *
127
         * @param os stream in which the error will be written
128
         * @param code content of the source file where the error is
129
         * @param target_line line where the error is
130
         * @param col_start where the error starts on the given line
131
         * @param sym_size bad expression that triggered the error
132
         * @param whole_line when true, underline the whole line, disregarding col_start and sym_size
133
         * @param colorize generate colors or not
134
         */
135
        ARK_API void makeContext(std::ostream& os, const std::string& code, std::size_t target_line, std::size_t col_start, std::size_t sym_size, bool whole_line, bool colorize);
136

137
        /**
138
         * @brief Helper used by the compiler to generate a colorized context from a node
139
         *
140
         * @param message error message to be included in the context
141
         * @param node AST node with the error
142
         * @return std::string
143
         */
144
        ARK_API std::string makeContextWithNode(const std::string& message, const internal::Node& node);
145

146
        /**
147
         * @brief Generate a diagnostic from an error and print it to the standard output
148
         *
149
         * @param e code error
150
         * @param os output stream
151
         * @param colorize generate colors or not
152
         */
153
        ARK_API void generate(const CodeError& e, std::ostream& os = std::cout, bool colorize = true);
154
    }
155
}
156

157
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc