mirror of
https://github.com/NotAShelf/Hyprdoctor.git
synced 2024-11-22 21:31:11 +00:00
cross-reference found errors against error database
This commit is contained in:
parent
00eba3c0a6
commit
0601487ff5
5 changed files with 59 additions and 6 deletions
4
Makefile
4
Makefile
|
@ -1,7 +1,7 @@
|
||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -Wall -std=c++11
|
CXXFLAGS = -Wall -std=c++17
|
||||||
TARGET = Hyprdoctor
|
TARGET = Hyprdoctor
|
||||||
SRCS = main.cpp src/utils/environment.cpp src/utils/file_parser.cpp
|
SRCS = main.cpp src/utils/environment.cpp src/utils/file_parser.cpp src/utils/json_parser.cpp
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
all: $(TARGET);
|
all: $(TARGET);
|
||||||
|
|
7
database/exampleIssue.json
Normal file
7
database/exampleIssue.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"ID": 1,
|
||||||
|
"name": "Example Issue",
|
||||||
|
"resources": ["resource1", "resource2", "resource3"],
|
||||||
|
"description": "This is a long string that can contain multiple sentences or paragraphs.",
|
||||||
|
"errors": ["error1", "error2", "error3"]
|
||||||
|
}
|
13
main.cpp
13
main.cpp
|
@ -1,18 +1,23 @@
|
||||||
|
|
||||||
#include "src/utils/environment.h"
|
#include "src/utils/environment.h"
|
||||||
#include "src/utils/file_parser.h"
|
#include "src/utils/file_parser.h"
|
||||||
|
#include "src/utils/json_parser.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const char *envVar = getEnvVar("PATH");
|
const char *envVar = getEnvVar("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
|
||||||
// try opening the log file
|
// try opening the log file
|
||||||
try {
|
try {
|
||||||
std::string filePath = "/tmp/hypr/" + std::string(envVar);
|
std::string filePath = "/tmp/hypr/" + std::string(envVar);
|
||||||
std::vector<std::string> errLines = readErrLines(filePath);
|
std::vector<std::string> errLines = readErrLines(filePath);
|
||||||
|
|
||||||
// print [ERR] lines, which are caught errors that we prioritize
|
// associate each error with the issue ID and name
|
||||||
for (const auto &line : errLines) {
|
std::vector<std::pair<int, std::string>> issues =
|
||||||
std::cout << line << std::endl;
|
findErrorsInJsonFiles(errLines, "database");
|
||||||
|
|
||||||
|
for (const auto &[id, name] : issues) {
|
||||||
|
std::cout << "Issue ID: " << id << ", Name: " << name << std::endl;
|
||||||
}
|
}
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cerr << "Error: " << e.what() << std::endl;
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
|
29
src/utils/json_parser.cpp
Normal file
29
src/utils/json_parser.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include "json_parser.h"
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<std::pair<int, std::string>>
|
||||||
|
findErrorsInJsonFiles(const std::vector<std::string> &errLines,
|
||||||
|
const std::string &dirPath) {
|
||||||
|
std::vector<std::pair<int, std::string>> issues;
|
||||||
|
|
||||||
|
for (const auto &entry : std::filesystem::directory_iterator(dirPath)) {
|
||||||
|
std::ifstream file(entry.path());
|
||||||
|
nlohmann::json j;
|
||||||
|
file >> j;
|
||||||
|
|
||||||
|
if (j.contains("errors") && j["errors"].is_array()) {
|
||||||
|
for (const auto &error : j["errors"]) {
|
||||||
|
if (std::find(errLines.begin(), errLines.end(), error) !=
|
||||||
|
errLines.end()) {
|
||||||
|
issues.push_back({j["ID"], j["name"]});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return issues;
|
||||||
|
}
|
12
src/utils/json_parser.h
Normal file
12
src/utils/json_parser.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef JSON_PARSER_H
|
||||||
|
#define JSON_PARSER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<std::pair<int, std::string>>
|
||||||
|
findErrorsInJsonFiles(const std::vector<std::string> &errLines,
|
||||||
|
const std::string &dirPath);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue