From 9a42b6619202ff1eca64f9bb2a5dc0086c0d2b60 Mon Sep 17 00:00:00 2001
From: Mattias Ajander <mattias@ajander.se>
Date: Sun, 30 Mar 2025 23:08:22 +0200
Subject: [PATCH] Added FileError and special case for missing filenames in
 trace

---
 include/utils/Exception.h | 14 ++++++++++++++
 source/utils/Exception.cc |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/include/utils/Exception.h b/include/utils/Exception.h
index 40d423b..e856856 100644
--- a/include/utils/Exception.h
+++ b/include/utils/Exception.h
@@ -107,4 +107,18 @@ public:
     RuntimeError(const String& message) : FunkError(SourceLocation{"", 0, 0}, "Runtime error", message) {}
 };
 
+/**
+ * @brief Exception class for file-related errors.
+ * Thrown when there is an issue with file operations.
+ */
+class FileError : public std::runtime_error
+{
+public:
+    /**
+     * @brief Constructs a FileError with message.
+     * @param message Description of the error
+     */
+    FileError(const String& message) : std::runtime_error(message) {}
+};
+
 } // namespace funk
diff --git a/source/utils/Exception.cc b/source/utils/Exception.cc
index e022b63..dff1c44 100644
--- a/source/utils/Exception.cc
+++ b/source/utils/Exception.cc
@@ -15,6 +15,8 @@ const SourceLocation& FunkError::get_location() const
 
 String FunkError::trace() const
 {
+    if (location.filename.empty()) { return what(); }
+
     std::ostringstream os;
     os << type << " in file " << location.filename << " at line " << location.line << ", column " << location.column
        << '\n';
-- 
GitLab