Skip to content

Commit

Permalink
feat: improve error logging in module resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
pmqueiroz committed Dec 1, 2024
1 parent 856cc93 commit 541865a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions exception/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ var Messages = map[string]string{
"RT035": "cannot use '%s' as a type",
"RT036": "enum member expects to be called with arguments",
"GN001": "cannot find module '%s'",
"GN002": "unable to load file '%s'. module does not exits. path: %s",
}
13 changes: 10 additions & 3 deletions interpreter/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/pmqueiroz/umbra/ast"
"github.com/pmqueiroz/umbra/environment"
"github.com/pmqueiroz/umbra/exception"
"github.com/pmqueiroz/umbra/helpers"
"github.com/pmqueiroz/umbra/native"
"github.com/pmqueiroz/umbra/tokens"
Expand All @@ -17,9 +18,15 @@ type Module struct {
}

func ResolveModule(module string) (string, error) {
content, err := helpers.ReadFile(fmt.Sprintf("%s/lib/%s.u", os.Getenv("UMBRA_PATH"), module))
path := fmt.Sprintf("%s/lib/%s.u", os.Getenv("UMBRA_PATH"), module)

return content, err
content, err := helpers.ReadFile(path)

if err != nil {
return content, exception.NewGenericError("GN002", module, path)
}

return content, nil
}

func LoadInternalModule(name string, namespace *environment.Environment) error {
Expand All @@ -34,7 +41,7 @@ func LoadBuiltInModule(path string, namespace *environment.Environment) error {
content, err := ResolveModule(path)

if err != nil {
return fmt.Errorf("unable to include %s. module does not exits", path)
return err
}

tokens, err := tokens.Tokenize(content)
Expand Down

0 comments on commit 541865a

Please sign in to comment.