Skip to main content
Version: Next

src/sydra/query/errors.zig

Purpose

Defines diagnostic structures for sydraQL validation.

See also

Definition index (public)

pub const ErrorCode = enum { ... }

Current codes:

  • time_range_required
  • unsupported_fill_policy
  • invalid_function_arity
  • invalid_syntax
  • unimplemented

Intended meaning (by convention in this repo):

  • time_range_required — missing or insufficient time predicate
  • unsupported_fill_policy — fill clause exists but the policy is not supported
  • invalid_function_arity — a function was called with the wrong number of arguments
  • invalid_syntax — generic “this construct is not valid” diagnostic used by the validator
  • unimplemented — reserved for “recognized but not implemented yet”

pub const Diagnostic

  • code: ErrorCode
  • message: []const u8owned allocation
  • span: ?Span

Ownership note:

  • initDiagnostic clones message using the provided allocator.
  • Callers are responsible for freeing diag.message (the validator does this in Analyzer.deinit).

pub const DiagnosticList

Alias: std.ArrayListUnmanaged(Diagnostic)

pub fn initDiagnostic(alloc, code, message, span) !Diagnostic

Clones message into an owned allocation and returns a Diagnostic.

Tests

Inline tests validate that initDiagnostic clones the message buffer.

Code excerpt

src/sydra/query/errors.zig
pub const ErrorCode = enum {
time_range_required,
unsupported_fill_policy,
invalid_function_arity,
invalid_syntax,
unimplemented,
};

pub const Diagnostic = struct {
code: ErrorCode,
message: []const u8,
span: ?common.Span = null,
};

pub const DiagnosticList = std.ArrayListUnmanaged(Diagnostic);

pub fn initDiagnostic(alloc: std.mem.Allocator, code: ErrorCode, message: []const u8, span: ?common.Span) !Diagnostic {
const owned = try alloc.dupe(u8, message);
return .{ .code = code, .message = owned, .span = span };
}