Skip to content

Commit e553b12

Browse files
committed
Improve error diagnostics and add sanitizer run support
2 parents 14342ab + 221dced commit e553b12

71 files changed

Lines changed: 3637 additions & 2102 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/vix/cli/commands/check/CheckDetail.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ namespace vix::commands::CheckCommand::detail
8787
/// Enable UBSan only.
8888
bool enableUbsanOnly = false;
8989

90+
/// Enable ThreadSanitizer only.
91+
bool enableThreadSanitizer = false;
92+
9093
/// Enable SQLite backend.
9194
bool withSqlite = false;
9295

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ namespace vix::commands::RunCommand::detail
130130
bool forceServerLike = false;
131131
bool forceScriptLike = false;
132132

133-
bool enableSanitizers = false; // ASan + UBSan
134-
bool enableUbsanOnly = false; // UBSan only
133+
bool enableSanitizers = false; // ASan + UBSan
134+
bool enableUbsanOnly = false; // UBSan only
135+
bool enableThreadSanitizer = false; // TSan only
135136

136137
bool withSqlite = false;
137138
bool withMySql = false;
@@ -451,6 +452,27 @@ namespace vix::commands::RunCommand::detail
451452
return opt.timeoutSec;
452453
}
453454

455+
/**
456+
* @brief Checks whether any sanitizer mode is enabled.
457+
*
458+
* This includes:
459+
* - ASan+UBSan
460+
* - UBSan-only
461+
* - ThreadSanitizer
462+
*
463+
* @param enableSanitizers True when ASan+UBSan mode is enabled.
464+
* @param enableUbsanOnly True when UBSan-only mode is enabled.
465+
* @param enableThreadSanitizer True when ThreadSanitizer mode is enabled.
466+
* @return True if any sanitizer mode is active.
467+
*/
468+
inline bool want_any_sanitizer(
469+
bool enableSanitizers,
470+
bool enableUbsanOnly,
471+
bool enableThreadSanitizer) noexcept
472+
{
473+
return enableSanitizers || enableUbsanOnly || enableThreadSanitizer;
474+
}
475+
454476
/**
455477
* @brief Normalize a cwd string to an absolute path when possible.
456478
*/

include/vix/cli/commands/run/RunScriptHelpers.hpp

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,147 @@
1212
*/
1313
#ifndef VIX_RUN_SCRIPT_HELPERS_HPP
1414
#define VIX_RUN_SCRIPT_HELPERS_HPP
15+
1516
#include <filesystem>
1617
#include <optional>
1718
#include <string>
1819
#include <string_view>
1920
#include <vector>
21+
2022
namespace vix::commands::RunCommand::detail
2123
{
2224
namespace fs = std::filesystem;
25+
26+
/**
27+
* @brief Prints the watch-mode restart banner.
28+
*
29+
* @param path Path of the file that triggered the restart.
30+
* @param label Message displayed while rebuilding or restarting.
31+
*/
2332
void print_watch_restart_banner(const fs::path &path, std::string_view label);
24-
std::string sanitizer_mode_string(bool enableSanitizers, bool enableUbsanOnly);
25-
bool want_sanitizers(bool enableSanitizers, bool enableUbsanOnly);
33+
34+
/**
35+
* @brief Checks whether ASan+UBSan or UBSan-only mode is enabled.
36+
*
37+
* This helper intentionally does not include ThreadSanitizer.
38+
* For ASan, UBSan, and TSan together, use want_any_sanitizer()
39+
* from RunDetail.hpp.
40+
*
41+
* @param enableSanitizers True when ASan+UBSan mode is enabled.
42+
* @param enableUbsanOnly True when UBSan-only mode is enabled.
43+
* @return True if ASan+UBSan or UBSan-only mode is active.
44+
*/
45+
bool want_sanitizers(
46+
bool enableSanitizers,
47+
bool enableUbsanOnly);
48+
49+
/**
50+
* @brief Returns the sanitizer mode string used by generated CMake projects.
51+
*
52+
* Possible return values:
53+
* - "asan_ubsan"
54+
* - "ubsan"
55+
* - "tsan"
56+
* - "none"
57+
*
58+
* @param enableSanitizers True when ASan+UBSan mode is enabled.
59+
* @param enableUbsanOnly True when UBSan-only mode is enabled.
60+
* @param enableThreadSanitizer True when ThreadSanitizer mode is enabled.
61+
* @return Sanitizer mode string.
62+
*/
63+
std::string sanitizer_mode_string(
64+
bool enableSanitizers,
65+
bool enableUbsanOnly,
66+
bool enableThreadSanitizer);
67+
68+
/**
69+
* @brief Builds the configuration signature for generated script CMake projects.
70+
*
71+
* The signature is used to decide whether a cached generated CMake project
72+
* must be reconfigured. It includes every option that can affect the produced
73+
* binary, including sanitizer mode, script flags, and optional database support.
74+
*
75+
* @param useVixRuntime True if the script links against the Vix runtime.
76+
* @param enableSanitizers True when ASan+UBSan mode is enabled.
77+
* @param enableUbsanOnly True when UBSan-only mode is enabled.
78+
* @param enableThreadSanitizer True when ThreadSanitizer mode is enabled.
79+
* @param scriptFlags Compiler/linker flags forwarded to script mode.
80+
* @param withSqlite True if SQLite support is enabled.
81+
* @param withMySql True if MySQL support is enabled.
82+
* @return Stable configuration signature string.
83+
*/
2684
std::string make_script_config_signature(
2785
bool useVixRuntime,
2886
bool enableSanitizers,
2987
bool enableUbsanOnly,
88+
bool enableThreadSanitizer,
3089
const std::vector<std::string> &scriptFlags,
3190
bool withSqlite,
3291
bool withMySql);
92+
93+
/**
94+
* @brief Starts the watch-mode spinner.
95+
*
96+
* @param label Text displayed next to the spinner.
97+
*/
3398
void watch_spinner_start(std::string label);
99+
100+
/**
101+
* @brief Stops the watch-mode spinner.
102+
*/
34103
void watch_spinner_stop();
104+
105+
/**
106+
* @brief Temporarily stops the watch spinner before printing output.
107+
*/
35108
void watch_spinner_pause_for_output();
109+
36110
#ifndef _WIN32
37-
void apply_sanitizer_env_if_needed(bool enableSanitizers, bool enableUbsanOnly);
111+
/**
112+
* @brief Applies sanitizer-related runtime environment variables.
113+
*
114+
* On POSIX systems, this configures ASan, UBSan, or TSan environment
115+
* variables so sanitizer reports are deterministic and easier for Vix
116+
* to capture and convert into friendly diagnostics.
117+
*
118+
* @param enableSanitizers True when ASan+UBSan mode is enabled.
119+
* @param enableUbsanOnly True when UBSan-only mode is enabled.
120+
* @param enableThreadSanitizer True when ThreadSanitizer mode is enabled.
121+
*/
122+
void apply_sanitizer_env_if_needed(
123+
bool enableSanitizers,
124+
bool enableUbsanOnly,
125+
bool enableThreadSanitizer);
38126
#endif
39127

128+
/**
129+
* @brief Finds a precompiled Vix header if available.
130+
*
131+
* @return Path to the PCH file, or std::nullopt if not found.
132+
*/
40133
std::optional<fs::path> find_vix_pch();
134+
135+
/**
136+
* @brief Finds the installed Vix include directory.
137+
*
138+
* @return Path to the include directory, or std::nullopt if not found.
139+
*/
41140
std::optional<fs::path> find_vix_include_dir();
141+
142+
/**
143+
* @brief Finds the installed Vix library.
144+
*
145+
* @return Path to the Vix library, or std::nullopt if not found.
146+
*/
42147
std::optional<fs::path> find_vix_lib();
148+
149+
/**
150+
* @brief Finds all installed Vix module libraries.
151+
*
152+
* @return List of discovered Vix module library paths.
153+
*/
43154
std::vector<fs::path> find_vix_all_module_libs();
44155

45156
} // namespace vix::commands::RunCommand::detail
157+
46158
#endif

include/vix/cli/errors/build/BuildErrorDetectors.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
namespace vix::cli::errors::build
2020
{
2121
bool handleBuildErrors(std::string_view log);
22-
}
22+
} // namespace vix::cli::errors::build
2323

2424
#endif

include/vix/cli/errors/build/CMakeBuildErrors.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
namespace vix::cli::errors::build
2020
{
2121
bool handleCMakeBuildError(std::string_view log);
22-
}
22+
} // namespace vix::cli::errors::build
2323

2424
#endif

include/vix/cli/errors/rules/UncaughtExceptionRule.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
*
3+
* @file UncaughtExceptionRule.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
113
#pragma once
214

315
#include <filesystem>

include/vix/cli/errors/runtime/RuntimeRuleUtils.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,38 @@
2222

2323
namespace vix::cli::errors::runtime
2424
{
25+
struct RuntimeLocation
26+
{
27+
std::filesystem::path file{};
28+
int line = 0;
29+
int column = 1;
30+
31+
[[nodiscard]] bool valid() const noexcept
32+
{
33+
return !file.empty() && line > 0;
34+
}
35+
};
36+
2537
bool icontains(const std::string &text, const std::string &needle);
2638

2739
std::string strip_line_comment(const std::string &line);
2840

2941
std::optional<std::vector<std::string>> read_file_lines(
3042
const std::filesystem::path &path);
3143

44+
RuntimeLocation find_best_runtime_location(
45+
const std::string &log,
46+
const std::filesystem::path &sourceFile);
47+
48+
RuntimeLocation find_best_runtime_location_or_source_hint(
49+
const std::string &log,
50+
const std::filesystem::path &sourceFile,
51+
const std::vector<std::string> &sourcePatterns);
52+
53+
std::string make_at_text(
54+
const RuntimeLocation &location,
55+
const std::filesystem::path &sourceFile);
56+
3257
vix::cli::errors::CompilerError make_runtime_location(
3358
const std::filesystem::path &sourceFile,
3459
int line,

0 commit comments

Comments
 (0)