diff --git a/src/build/Build.go b/src/build/Build.go index eea57f0..f73045a 100644 --- a/src/build/Build.go +++ b/src/build/Build.go @@ -7,7 +7,6 @@ import ( "git.akyoto.dev/cli/q/src/compiler" "git.akyoto.dev/cli/q/src/elf" - "git.akyoto.dev/cli/q/src/errors" ) // Build describes a compiler build. @@ -26,16 +25,6 @@ func New(directory string) *Build { // Run parses the input files and generates an executable file. func (build *Build) Run() error { - stat, err := os.Stat(build.Directory) - - if err != nil { - return err - } - - if !stat.IsDir() { - return &errors.InvalidDirectory{Path: build.Directory} - } - functions, err := compiler.Compile(build.Directory) if err != nil { diff --git a/src/compiler/Scan.go b/src/compiler/Scan.go index 4e55afd..1c52ba4 100644 --- a/src/compiler/Scan.go +++ b/src/compiler/Scan.go @@ -28,7 +28,7 @@ func Scan(path string) (<-chan *Function, <-chan error) { func scan(path string, functions chan<- *Function, errors chan<- error) { wg := sync.WaitGroup{} - directory.Walk(path, func(name string) { + err := directory.Walk(path, func(name string) { if !strings.HasSuffix(name, ".q") { return } @@ -46,6 +46,10 @@ func scan(path string, functions chan<- *Function, errors chan<- error) { }() }) + if err != nil { + errors <- err + } + wg.Wait() } diff --git a/src/directory/Walk.go b/src/directory/Walk.go index f871c64..e2cc495 100644 --- a/src/directory/Walk.go +++ b/src/directory/Walk.go @@ -9,11 +9,11 @@ const blockSize = 4096 // Walk calls your callback function for every file name inside the directory. // It doesn't distinguish between files and directories. -func Walk(directory string, callBack func(string)) { +func Walk(directory string, callBack func(string)) error { fd, err := syscall.Open(directory, 0, 0) if err != nil { - panic(err) + return err } defer syscall.Close(fd) @@ -23,7 +23,7 @@ func Walk(directory string, callBack func(string)) { n, err := syscall.ReadDirent(fd, buffer) if err != nil { - panic(err) + return err } if n <= 0 { @@ -58,4 +58,6 @@ func Walk(directory string, callBack func(string)) { } } } + + return nil }