@@ -228,10 +228,21 @@ pub const Context = struct {
228
228
pub fn parse_enum (ctx : Context , comptime E : type ) Environment.ParseError ! E {
229
229
if (@typeInfo (E ) != .@"enum" )
230
230
@compileError ("get_enum requires an enum type!" );
231
- return std .meta .stringToEnum (
231
+ const tag_name = try ctx .parse_string ();
232
+ const converted = std .meta .stringToEnum (
232
233
E ,
233
- try ctx .parse_string (),
234
- ) orelse return error .InvalidEnumTag ;
234
+ tag_name ,
235
+ );
236
+ if (converted ) | ok |
237
+ return ok ;
238
+ std .debug .print ("detected invalid enum tag for {s}: \" {}\" \n " , .{ @typeName (E ), std .zig .fmtEscapes (tag_name ) });
239
+ std .debug .print ("valid options are:\n " , .{});
240
+
241
+ for (std .enums .values (E )) | val | {
242
+ std .debug .print ("- '{s}'\n " , .{@tagName (val )});
243
+ }
244
+
245
+ return error .InvalidEnumTag ;
235
246
}
236
247
237
248
pub fn parse_integer (ctx : Context , comptime I : type , base : u8 ) Environment.ParseError ! I {
@@ -355,14 +366,25 @@ const Environment = struct {
355
366
fn fetch_file (io : * const Parser.IO , allocator : std.mem.Allocator , path : []const u8 ) error { FileNotFound , IoError , OutOfMemory , InvalidPath }! []const u8 {
356
367
const env : * const Environment = @fieldParentPtr ("io" , io );
357
368
358
- const name : FileName = .{ .root_dir = env .include_base , .rel_path = path };
359
- try name .declare_dependency ();
360
-
361
- return env .include_base .readFileAlloc (allocator , path , max_script_size ) catch | err | switch (err ) {
369
+ const contents = env .include_base .readFileAlloc (allocator , path , max_script_size ) catch | err | switch (err ) {
362
370
error .OutOfMemory = > return error .OutOfMemory ,
363
- error .FileNotFound = > return error .FileNotFound ,
371
+ error .FileNotFound = > {
372
+ const ctx = Context { .env = @constCast (env ) };
373
+ var buffer : [std .fs .max_path_bytes ]u8 = undefined ;
374
+ try ctx .report_nonfatal_error ("failed to open file: \" {}/{}\" " , .{
375
+ std .zig .fmtEscapes (env .include_base .realpath ("." , & buffer ) catch return error .FileNotFound ),
376
+ std .zig .fmtEscapes (path ),
377
+ });
378
+ return error .FileNotFound ;
379
+ },
364
380
else = > return error .IoError ,
365
381
};
382
+ errdefer allocator .free (contents );
383
+
384
+ const name : FileName = .{ .root_dir = env .include_base , .rel_path = path };
385
+ try name .declare_dependency ();
386
+
387
+ return contents ;
366
388
}
367
389
368
390
fn resolve_var (io : * const Parser.IO , name : []const u8 ) error {UnknownVariable }! []const u8 {
0 commit comments