-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResourceNotFoundRule.cpp
More file actions
87 lines (75 loc) · 2.2 KB
/
Copy pathResourceNotFoundRule.cpp
File metadata and controls
87 lines (75 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
*
* @file ResourceNotFoundRule.cpp
* @author Gaspard Kirira
*
* Copyright 2025, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
*/
#include <vix/cli/errors/runtime/IRuntimeErrorRule.hpp>
#include <vix/cli/errors/runtime/RuntimeRuleUtils.hpp>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <vix/cli/Style.hpp>
using namespace vix::cli::style;
namespace vix::cli::errors::runtime
{
namespace
{
bool looks_like_resource_not_found_log(const std::string &log)
{
return icontains(log, "asset file not found") ||
icontains(log, "resource not found") ||
icontains(log, "file not found") ||
icontains(log, "no such file or directory");
}
bool looks_like_load_failure(const std::string &log)
{
return icontains(log, "load failed") ||
icontains(log, "failed to load") ||
icontains(log, "open failed") ||
icontains(log, "failed to open");
}
} // namespace
class ResourceNotFoundRule final : public IRuntimeErrorRule
{
public:
bool match(
const std::string &log,
const std::filesystem::path &sourceFile) const override
{
(void)sourceFile;
return looks_like_resource_not_found_log(log) ||
(looks_like_load_failure(log) && icontains(log, "not found"));
}
bool handle(
const std::string &log,
const std::filesystem::path &sourceFile) const override
{
(void)log;
(void)sourceFile;
std::cerr << RED
<< "runtime error: required resource not found"
<< RESET << "\n";
print_runtime_hints_and_at(
{
"check the path used to load the resource",
"ensure the file exists relative to the working directory or configured asset root",
},
"");
return true;
}
};
std::unique_ptr<IRuntimeErrorRule> makeResourceNotFoundRule()
{
return std::make_unique<ResourceNotFoundRule>();
}
} // namespace vix::cli::errors::runtime