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

ArkScript-lang / Ark / 14640812317

24 Apr 2025 11:46AM UTC coverage: 83.196% (+2.8%) from 80.417%
14640812317

Pull #530

github

web-flow
Merge 718abfdf5 into 32828a045
Pull Request #530: Feat/inst locations

290 of 380 new or added lines in 20 files covered. (76.32%)

7 existing lines in 3 files now uncovered.

6560 of 7885 relevant lines covered (83.2%)

79291.33 hits per line

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

63.64
/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

NEW
39
        [[nodiscard]] virtual std::string details(bool colorize [[maybe_unused]]) const
×
NEW
40
        {
×
NEW
41
            return what();
×
NEW
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
     */
NEW
61
    class ARK_API AssertionFailed final : public Error
×
62
    {
63
    public:
NEW
64
        explicit AssertionFailed(const std::string& message) :
×
NEW
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) + "\n" + details)
28✔
75
        {}
84✔
76

77
        NestedError(const std::exception& e, const std::string& details) :
30✔
78
            Error("NestedError"),
30✔
79
            m_details(e.what() + ("\n" + details))
30✔
80
        {}
90✔
81

82
        [[nodiscard]] const char* what() const noexcept override
58✔
83
        {
58✔
84
            return m_details.c_str();
58✔
85
        }
86

87
    private:
88
        std::string m_details;
89
    };
90

91
    /**
92
     * @brief CodeError thrown by the compiler (parser, macro processor, optimizer, and compiler itself)
93
     *
94
     */
95
    struct ARK_API CodeError final : Error
113✔
96
    {
97
        const std::string filename;
98
        const std::size_t line;
99
        const std::size_t col;
100
        const std::string expr;
101
        const std::optional<internal::utf8_char_t> symbol;
102

103
        CodeError(
113✔
104
            const std::string& what,
105
            std::string filename_,
106
            const std::size_t lineNum,
107
            const std::size_t column,
108
            std::string exp,
109
            const std::optional<internal::utf8_char_t> opt_sym = std::nullopt) :
110
            Error(what),
113✔
111
            filename(std::move(filename_)), line(lineNum), col(column), expr(std::move(exp)), symbol(opt_sym)
113✔
112
        {}
339✔
113
    };
114

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

130
        /**
131
         * @brief Helper used by the compiler to generate a colorized context from a node
132
         *
133
         * @param message error message to be included in the context
134
         * @param node AST node with the error
135
         * @return std::string
136
         */
137
        ARK_API std::string makeContextWithNode(const std::string& message, const internal::Node& node);
138

139
        /**
140
         * @brief Generate a diagnostic from an error and print it to the standard output
141
         *
142
         * @param e code error
143
         * @param os output stream
144
         * @param colorize generate colors or not
145
         */
146
        ARK_API void generate(const CodeError& e, std::ostream& os = std::cout, bool colorize = true);
147
    }
148
}
149

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