mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
Merge pull request #8341 from FabHof/file_errors
roc check: Add report for file open errors
This commit is contained in:
commit
70432d9dab
1 changed files with 27 additions and 1 deletions
|
|
@ -751,7 +751,33 @@ pub const BuildEnv = struct {
|
|||
// Read source
|
||||
const file_abs = try std.fs.path.resolve(self.gpa, &.{file_path});
|
||||
defer self.gpa.free(file_abs);
|
||||
const src = try std.fs.cwd().readFileAlloc(self.gpa, file_abs, std.math.maxInt(usize));
|
||||
const src = std.fs.cwd().readFileAlloc(self.gpa, file_abs, std.math.maxInt(usize)) catch |err| {
|
||||
const report = blk: switch (err) {
|
||||
error.FileNotFound => {
|
||||
var report = Report.init(self.gpa, "FILE NOT FOUND", .fatal);
|
||||
try report.document.addText("I could not find the file ");
|
||||
try report.document.addAnnotated(file_abs, .path);
|
||||
try report.document.addLineBreak();
|
||||
try report.document.addText("Make sure the file exists and you do not have any typos in its name or path.");
|
||||
break :blk report;
|
||||
},
|
||||
|
||||
else => {
|
||||
var report = Report.init(self.gpa, "COULD NOT READ FILE", .fatal);
|
||||
try report.document.addText("I could not read the file ");
|
||||
try report.document.addAnnotated(file_abs, .path);
|
||||
try report.document.addLineBreak();
|
||||
try report.document.addText("I did get the following error: ");
|
||||
try report.addErrorMessage(@errorName(err));
|
||||
try report.document.addText("Make sure the file can be read.");
|
||||
break :blk report;
|
||||
},
|
||||
};
|
||||
self.sink.emitReport("main", file_abs, report);
|
||||
try self.sink.buildOrder(&[_][]const u8{"main"}, &[_][]const u8{file_abs}, &[_]u32{0});
|
||||
self.sink.tryEmit();
|
||||
return err;
|
||||
};
|
||||
defer self.gpa.free(src);
|
||||
|
||||
var env = try ModuleEnv.init(self.gpa, src);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue