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

ArkScript-lang / Ark / 14647441324

24 Apr 2025 05:07PM UTC coverage: 83.165% (+2.7%) from 80.417%
14647441324

push

github

SuperFola
feat(vm): compressing identical traces when displaying the stacktrace of an error

21 of 21 new or added lines in 1 file covered. (100.0%)

270 existing lines in 10 files now uncovered.

6580 of 7912 relevant lines covered (83.16%)

79046.5 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
 * @version 1.3
6
 * @date 2020-10-27
7
 *
8
 * @copyright Copyright (c) 2020-2025
9
 *
10
 */
11

12
#ifndef INCLUDE_ARK_EXCEPTIONS_HPP
13
#define INCLUDE_ARK_EXCEPTIONS_HPP
14

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

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

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

32
    class ARK_API Error : public std::runtime_error
199✔
33
    {
34
    public:
35
        explicit Error(const std::string& message) :
199✔
36
            std::runtime_error(message)
199✔
37
        {}
398✔
38

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

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

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

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

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

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

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

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

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

123
    namespace Diagnostics
124
    {
125
        /**
126
         * @brief Helper to create a colorized context to report errors to the user
127
         *
128
         * @param os stream in which the error will be written
129
         * @param code content of the source file where the error is
130
         * @param target_line line where the error is
131
         * @param col_start where the error starts on the given line
132
         * @param sym_size bad expression that triggered the error
133
         * @param whole_line when true, underline the whole line, disregarding col_start and sym_size
134
         * @param colorize generate colors or not
135
         */
136
        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);
137

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

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

158
#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