Moved global error to lib and fuse to a unique one

This commit is contained in:
2025-01-12 00:37:57 +01:00
parent c0e8b07025
commit 955aff0d09
16 changed files with 83 additions and 98 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ const DataType = dtype.DataType;
// TODO: Put this in a data structure directory
const ZipponError = @import("../errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
/// This is the [] part
pub const AdditionalData = @This();
+1 -1
View File
@@ -10,7 +10,7 @@
const std = @import("std");
const s2t = @import("dtype").s2t;
const ZipponError = @import("../errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
const DataType = @import("dtype").DataType;
const DateTime = @import("dtype").DateTime;
const UUID = @import("dtype").UUID;
+1 -1
View File
@@ -21,7 +21,7 @@
const std = @import("std");
const AdditionalData = @import("additionalData.zig").AdditionalData;
const ZipponError = @import("../errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
pub const JsonString = struct {
slice: []const u8 = "",
+1 -1
View File
@@ -8,7 +8,7 @@ const DataType = dtype.DataType;
const DateTime = dtype.DateTime;
const UUID = dtype.UUID;
const ZipponError = @import("errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
pub fn writeEntityTable(
writer: anytype,
-51
View File
@@ -1,51 +0,0 @@
// TODO: Only use a single and big ZipponError
pub const ZiQlParserError = error{
MemoryError,
SynthaxError,
MemberNotFound,
MemberMissing,
StructNotFound,
FeatureMissing,
ParsingValueError,
ConditionError,
WriteError,
AndOrError,
CantWriteEntity,
};
pub const SchemaParserError = error{
SynthaxError,
FeatureMissing,
ValueParsingError,
MemoryError,
};
pub const FileEngineError = error{
SchemaFileNotFound,
SchemaNotConform,
DATAFolderNotFound,
StructFolderNotFound,
CantMakeDir,
CantMakeFile,
CantOpenDir,
CantOpenFile,
MemoryError,
StreamError,
ReadError, // TODO: Only use stream
InvalidUUID,
InvalidDate,
InvalidFileIndex,
DirIterError,
WriteError,
FileStatError,
DeleteFileError,
RenameFileError,
StructNotFound,
MemberNotFound,
ZipponDataError,
AllocEncodError,
ThreadError,
};
pub const ZipponError = ZiQlParserError || FileEngineError || SchemaParserError;
+1 -1
View File
@@ -21,7 +21,7 @@ const RelationMap = @import("dataStructure/relationMap.zig");
const JsonString = @import("dataStructure/relationMap.zig").JsonString;
const ConditionValue = @import("dataStructure/filter.zig").ConditionValue;
const ZipponError = @import("errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
const config = @import("config");
const BUFFER_SIZE = config.BUFFER_SIZE;
+2 -2
View File
@@ -15,7 +15,7 @@ const ziqlTokenizer = @import("tokenizers/ziql.zig").Tokenizer;
const ziqlToken = @import("tokenizers/ziql.zig").Token;
const ziqlParser = @import("ziqlParser.zig");
const ZipponError = @import("errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
const config = @import("config");
const BUFFER_SIZE = config.BUFFER_SIZE;
@@ -86,7 +86,7 @@ pub const DBEngine = struct {
pub fn init(potential_main_path: ?[]const u8, potential_schema_path: ?[]const u8) DBEngine {
var self = DBEngine{};
self.thread_engine = ThreadEngine.init() catch @panic("TODO");
self.thread_engine = ThreadEngine.init();
const potential_main_path_or_environment_variable = potential_main_path orelse utils.getEnvVariable("ZIPPONDB_PATH");
if (potential_main_path_or_environment_variable) |main_path| {
+2 -1
View File
@@ -3,7 +3,6 @@ const zid = @import("ZipponData");
const Allocator = std.mem.Allocator;
const Parser = @import("schemaParser.zig");
const Tokenizer = @import("tokenizers/schema.zig").Tokenizer;
const ZipponError = @import("errors.zig").ZipponError;
const dtype = @import("dtype");
const DataType = dtype.DataType;
const AdditionalData = @import("dataStructure/additionalData.zig");
@@ -14,6 +13,8 @@ const UUID = dtype.UUID;
const UUIDFileIndex = @import("dataStructure/UUIDFileIndex.zig");
const FileEngine = @import("fileEngine.zig");
const ZipponError = @import("error").ZipponError;
// TODO: Create a schemaEngine directory and add this as core and the parser with it
const config = @import("config");
+32 -32
View File
@@ -10,7 +10,7 @@ const Loc = @import("tokenizers/shared/loc.zig").Loc;
const send = @import("utils.zig").send;
const printError = @import("utils.zig").printError;
const SchemaParserError = @import("errors.zig").SchemaParserError;
const ZipponError = @import("error").ZipponError;
const State = enum {
end,
@@ -60,15 +60,15 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.identifier => {
state = .expect_l_paren;
name = self.toker.getTokenSlice(token);
member_list.append("id") catch return SchemaParserError.MemoryError;
type_list.append(.self) catch return SchemaParserError.MemoryError;
member_list.append("id") catch return ZipponError.MemoryError;
type_list.append(.self) catch return ZipponError.MemoryError;
},
.eof => state = .end,
else => {
std.debug.print("{s}\n", .{self.toker.getTokenSlice(token)});
return printError(
"Error parsing schema: Expected a struct name",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -80,7 +80,7 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.l_paren => state = .expect_member_name,
else => return printError(
"Error parsing schema: Expected (",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -95,7 +95,7 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.r_paren => state = .add_struct,
else => return printError(
"Error parsing schema: Expected member name or )",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -105,10 +105,10 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.add_struct => {
struct_array.append(try SchemaStruct.init(
name,
member_list.toOwnedSlice() catch return SchemaParserError.MemoryError,
type_list.toOwnedSlice() catch return SchemaParserError.MemoryError,
member_list.toOwnedSlice() catch return ZipponError.MemoryError,
type_list.toOwnedSlice() catch return ZipponError.MemoryError,
try links.clone(),
)) catch return SchemaParserError.MemoryError;
)) catch return ZipponError.MemoryError;
links.deinit();
links = std.StringHashMap([]const u8).init(self.allocator);
@@ -122,7 +122,7 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.expect_member_name => {
state = .expect_two_dot;
member_list.append(self.toker.getTokenSlice(token)) catch return SchemaParserError.MemoryError;
member_list.append(self.toker.getTokenSlice(token)) catch return ZipponError.MemoryError;
member_token = token;
},
@@ -130,7 +130,7 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.two_dot => state = .expect_value_type,
else => return printError(
"Error parsing schema: Expected :",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -140,41 +140,41 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.expect_value_type => switch (token.tag) {
.type_int => {
state = .expect_comma;
type_list.append(.int) catch return SchemaParserError.MemoryError;
type_list.append(.int) catch return ZipponError.MemoryError;
},
.type_str => {
state = .expect_comma;
type_list.append(.str) catch return SchemaParserError.MemoryError;
type_list.append(.str) catch return ZipponError.MemoryError;
},
.type_float => {
state = .expect_comma;
type_list.append(.float) catch return SchemaParserError.MemoryError;
type_list.append(.float) catch return ZipponError.MemoryError;
},
.type_bool => {
state = .expect_comma;
type_list.append(.bool) catch return SchemaParserError.MemoryError;
type_list.append(.bool) catch return ZipponError.MemoryError;
},
.type_date => {
state = .expect_comma;
type_list.append(.date) catch return SchemaParserError.MemoryError;
type_list.append(.date) catch return ZipponError.MemoryError;
},
.type_time => {
state = .expect_comma;
type_list.append(.time) catch return SchemaParserError.MemoryError;
type_list.append(.time) catch return ZipponError.MemoryError;
},
.type_datetime => {
state = .expect_comma;
type_list.append(.datetime) catch return SchemaParserError.MemoryError;
type_list.append(.datetime) catch return ZipponError.MemoryError;
},
.identifier => {
state = .expect_comma;
type_list.append(.link) catch return SchemaParserError.MemoryError;
links.put(self.toker.getTokenSlice(member_token), self.toker.getTokenSlice(token)) catch return SchemaParserError.MemoryError;
type_list.append(.link) catch return ZipponError.MemoryError;
links.put(self.toker.getTokenSlice(member_token), self.toker.getTokenSlice(token)) catch return ZipponError.MemoryError;
},
.lr_bracket => state = .expext_array_type,
else => return printError(
"Error parsing schema: Expected data type",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -184,40 +184,40 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.expext_array_type => switch (token.tag) {
.type_int => {
state = .expect_comma;
type_list.append(.int_array) catch return SchemaParserError.MemoryError;
type_list.append(.int_array) catch return ZipponError.MemoryError;
},
.type_str => {
state = .expect_comma;
type_list.append(.str_array) catch return SchemaParserError.MemoryError;
type_list.append(.str_array) catch return ZipponError.MemoryError;
},
.type_float => {
state = .expect_comma;
type_list.append(.float_array) catch return SchemaParserError.MemoryError;
type_list.append(.float_array) catch return ZipponError.MemoryError;
},
.type_bool => {
state = .expect_comma;
type_list.append(.bool_array) catch return SchemaParserError.MemoryError;
type_list.append(.bool_array) catch return ZipponError.MemoryError;
},
.type_date => {
state = .expect_comma;
type_list.append(.date_array) catch return SchemaParserError.MemoryError;
type_list.append(.date_array) catch return ZipponError.MemoryError;
},
.type_time => {
state = .expect_comma;
type_list.append(.time_array) catch return SchemaParserError.MemoryError;
type_list.append(.time_array) catch return ZipponError.MemoryError;
},
.type_datetime => {
state = .expect_comma;
type_list.append(.datetime_array) catch return SchemaParserError.MemoryError;
type_list.append(.datetime_array) catch return ZipponError.MemoryError;
},
.identifier => {
state = .expect_comma;
type_list.append(.link_array) catch return SchemaParserError.MemoryError;
links.put(self.toker.getTokenSlice(member_token), self.toker.getTokenSlice(token)) catch return SchemaParserError.MemoryError;
type_list.append(.link_array) catch return ZipponError.MemoryError;
links.put(self.toker.getTokenSlice(member_token), self.toker.getTokenSlice(token)) catch return ZipponError.MemoryError;
},
else => return printError(
"Error parsing schema: Expected data type",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
@@ -228,7 +228,7 @@ pub fn parse(self: *Parser, struct_array: *std.ArrayList(SchemaStruct)) !void {
.comma => state = .expect_member_name_OR_r_paren,
else => return printError(
"Error parsing schema: Expected ,",
SchemaParserError.SynthaxError,
ZipponError.SynthaxError,
self.toker.buffer,
token.loc.start,
token.loc.end,
+16 -17
View File
@@ -1,38 +1,37 @@
const std = @import("std");
const U64 = std.atomic.Value(u64);
const Pool = std.Thread.Pool;
const Allocator = std.mem.Allocator;
const ZipponError = @import("error").ZipponError;
const CPU_CORE = @import("config").CPU_CORE;
const log = std.log.scoped(.thread);
const ZipponError = @import("../errors.zig").ZipponError;
pub const Self = @This();
const allocator = std.heap.page_allocator;
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena.allocator();
var thread_arena: std.heap.ThreadSafeAllocator = undefined;
var thread_pool: Pool = undefined;
pub const ThreadEngine = @This();
thread_arena: *std.heap.ThreadSafeAllocator,
thread_pool: *Pool,
pub fn init() ZipponError!Self {
const thread_arena = allocator.create(std.heap.ThreadSafeAllocator) catch return ZipponError.MemoryError;
thread_arena.* = std.heap.ThreadSafeAllocator{
pub fn init() ThreadEngine {
thread_arena = std.heap.ThreadSafeAllocator{
.child_allocator = allocator,
};
const thread_pool = allocator.create(Pool) catch return ZipponError.MemoryError;
thread_pool.init(Pool.Options{
thread_pool.init(std.Thread.Pool.Options{
.allocator = thread_arena.allocator(),
.n_jobs = CPU_CORE,
}) catch return ZipponError.ThreadError;
}) catch @panic("=(");
return Self{
.thread_pool = thread_pool,
.thread_arena = thread_arena,
return ThreadEngine{
.thread_pool = &thread_pool,
.thread_arena = &thread_arena,
};
}
pub fn deinit(self: *Self) void {
self.thread_pool.deinit();
arena.deinit();
pub fn deinit(_: ThreadEngine) void {
thread_pool.deinit();
}
+1 -1
View File
@@ -1,5 +1,5 @@
const std = @import("std");
const ZipponError = @import("errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
const config = @import("config");
const log = std.log.scoped(.utils);
+1 -1
View File
@@ -18,7 +18,7 @@ const AdditionalDataMember = @import("dataStructure/additionalData.zig").Additio
const send = @import("utils.zig").send;
const printError = @import("utils.zig").printError;
const ZipponError = @import("errors.zig").ZipponError;
const ZipponError = @import("error").ZipponError;
const PRINT_STATE = @import("config").PRINT_STATE;
const log = std.log.scoped(.ziqlParser);