Improved error handling

This commit is contained in:
Eduard Urbach 2024-06-15 18:42:31 +02:00
parent 78cde0d0bd
commit a48f2868fb
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 71 additions and 60 deletions

View file

@ -6,7 +6,7 @@ import (
"strings"
"sync"
"git.akyoto.dev/cli/q/src/build/directory"
"git.akyoto.dev/cli/q/src/build/fs"
"git.akyoto.dev/cli/q/src/build/token"
"git.akyoto.dev/cli/q/src/errors"
)
@ -38,7 +38,7 @@ func scan(files []string, functions chan<- *Function, errors chan<- error) {
}
if stat.IsDir() {
err = directory.Walk(file, func(name string) {
err = fs.Walk(file, func(name string) {
if !strings.HasSuffix(name, ".q") {
return
}
@ -86,7 +86,7 @@ func scanFile(path string, functions chan<- *Function) error {
tokens := token.Tokenize(contents)
file := &File{
file := &fs.File{
Tokens: tokens,
Path: path,
}
@ -118,7 +118,7 @@ func scanFile(path string, functions chan<- *Function) error {
return nil
}
return errors.New(errors.ExpectedFunctionName, path, tokens, i)
return errors.New(errors.ExpectedFunctionName, file, tokens[i].Position)
}
// Function parameters
@ -138,7 +138,7 @@ func scanFile(path string, functions chan<- *Function) error {
groupLevel--
if groupLevel < 0 {
return errors.New(errors.MissingGroupStart, path, tokens, i)
return errors.New(errors.MissingGroupStart, file, tokens[i].Position)
}
i++
@ -152,11 +152,11 @@ func scanFile(path string, functions chan<- *Function) error {
if tokens[i].Kind == token.EOF {
if groupLevel > 0 {
return errors.New(errors.MissingGroupEnd, path, tokens, i)
return errors.New(errors.MissingGroupEnd, file, tokens[i].Position)
}
if paramsStart == -1 {
return errors.New(errors.ExpectedFunctionParameters, path, tokens, i)
return errors.New(errors.ExpectedFunctionParameters, file, tokens[i].Position)
}
return nil
@ -167,7 +167,7 @@ func scanFile(path string, functions chan<- *Function) error {
continue
}
return errors.New(errors.ExpectedFunctionParameters, path, tokens, i)
return errors.New(errors.ExpectedFunctionParameters, file, tokens[i].Position)
}
// Function definition
@ -187,7 +187,7 @@ func scanFile(path string, functions chan<- *Function) error {
blockLevel--
if blockLevel < 0 {
return errors.New(errors.MissingBlockStart, path, tokens, i)
return errors.New(errors.MissingBlockStart, file, tokens[i].Position)
}
i++
@ -201,11 +201,11 @@ func scanFile(path string, functions chan<- *Function) error {
if tokens[i].Kind == token.EOF {
if blockLevel > 0 {
return errors.New(errors.MissingBlockEnd, path, tokens, i)
return errors.New(errors.MissingBlockEnd, file, tokens[i].Position)
}
if bodyStart == -1 {
return errors.New(errors.ExpectedFunctionDefinition, path, tokens, i)
return errors.New(errors.ExpectedFunctionDefinition, file, tokens[i].Position)
}
return nil
@ -216,7 +216,7 @@ func scanFile(path string, functions chan<- *Function) error {
continue
}
return errors.New(errors.ExpectedFunctionDefinition, path, tokens, i)
return errors.New(errors.ExpectedFunctionDefinition, file, tokens[i].Position)
}
functions <- &Function{