Improved error handling
This commit is contained in:
parent
c4b28fb66e
commit
a7afd680da
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"git.akyoto.dev/cli/q/src/compiler"
|
"git.akyoto.dev/cli/q/src/compiler"
|
||||||
"git.akyoto.dev/cli/q/src/elf"
|
"git.akyoto.dev/cli/q/src/elf"
|
||||||
"git.akyoto.dev/cli/q/src/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Build describes a compiler build.
|
// Build describes a compiler build.
|
||||||
@ -26,16 +25,6 @@ func New(directory string) *Build {
|
|||||||
|
|
||||||
// Run parses the input files and generates an executable file.
|
// Run parses the input files and generates an executable file.
|
||||||
func (build *Build) Run() error {
|
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)
|
functions, err := compiler.Compile(build.Directory)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,7 +28,7 @@ func Scan(path string) (<-chan *Function, <-chan error) {
|
|||||||
func scan(path string, functions chan<- *Function, errors chan<- error) {
|
func scan(path string, functions chan<- *Function, errors chan<- error) {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
directory.Walk(path, func(name string) {
|
err := directory.Walk(path, func(name string) {
|
||||||
if !strings.HasSuffix(name, ".q") {
|
if !strings.HasSuffix(name, ".q") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -46,6 +46,10 @@ func scan(path string, functions chan<- *Function, errors chan<- error) {
|
|||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
errors <- err
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ const blockSize = 4096
|
|||||||
|
|
||||||
// Walk calls your callback function for every file name inside the directory.
|
// Walk calls your callback function for every file name inside the directory.
|
||||||
// It doesn't distinguish between files and directories.
|
// 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)
|
fd, err := syscall.Open(directory, 0, 0)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer syscall.Close(fd)
|
defer syscall.Close(fd)
|
||||||
@ -23,7 +23,7 @@ func Walk(directory string, callBack func(string)) {
|
|||||||
n, err := syscall.ReadDirent(fd, buffer)
|
n, err := syscall.ReadDirent(fd, buffer)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
@ -58,4 +58,6 @@ func Walk(directory string, callBack func(string)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user