Skip to content

Commit

Permalink
Replace cwd for nicer error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Feb 25, 2025
1 parent 10072c1 commit 7ee96d7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

/** @created_at: 2018-05-08 09:55 */

#include <filesystem>
#include <iostream>
#include "Codegen.hpp"
#include "utils.hpp"

int main (int argc, char *argv[]) {
auto cwd = std::filesystem::current_path().string();

try {
if (argc == 1) {
throw Error("REPL is not supported");
Expand Down Expand Up @@ -90,6 +94,8 @@ int main (int argc, char *argv[]) {
auto reader = Reader(*fileName);
auto lexer = Lexer(&reader);

cwd = std::filesystem::path(reader.path).parent_path().string();

if (isLex) {
while (true) {
auto [_, tok] = lexer.next();
Expand Down Expand Up @@ -135,7 +141,8 @@ int main (int argc, char *argv[]) {
Codegen::compile(output, result, arch, platform);
return EXIT_SUCCESS;
} catch (const Error &err) {
std::cerr << "Error: " << err.what() << std::endl;
auto message = std::string(err.what());
std::cerr << "Error: " << str_replace_all(message, cwd, ".") << std::endl;
return EXIT_FAILURE;
}
}

0 comments on commit 7ee96d7

Please sign in to comment.