mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
luahost: use sentinel ErrNoScript (#490)
Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package luahost
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -15,6 +16,9 @@ import (
|
|||||||
"github.com/yuin/gopher-lua/parse"
|
"github.com/yuin/gopher-lua/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNoScript signals that the Lua script file was not present.
|
||||||
|
var ErrNoScript error = errors.New("no script file present")
|
||||||
|
|
||||||
// Host of Lua extensions.
|
// Host of Lua extensions.
|
||||||
type Host struct {
|
type Host struct {
|
||||||
extHost *extension.Host
|
extHost *extension.Host
|
||||||
@@ -35,7 +39,7 @@ func New(conf config.Lua, extHost *extension.Host) (*Host, error) {
|
|||||||
// Pre-load, parse, and compile script.
|
// Pre-load, parse, and compile script.
|
||||||
if fi, err := os.Stat(scriptPath); err != nil {
|
if fi, err := os.Stat(scriptPath); err != nil {
|
||||||
logger.Info().Msg("Script file not found")
|
logger.Info().Msg("Script file not found")
|
||||||
return nil, nil
|
return nil, ErrNoScript
|
||||||
} else if fi.IsDir() {
|
} else if fi.IsDir() {
|
||||||
return nil, fmt.Errorf("lua script %v is a directory", scriptPath)
|
return nil, fmt.Errorf("lua script %v is a directory", scriptPath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func FullAssembly(conf *config.Root) (*Services, error) {
|
|||||||
// Configure extensions.
|
// Configure extensions.
|
||||||
extHost := extension.NewHost()
|
extHost := extension.NewHost()
|
||||||
luaHost, err := luahost.New(conf.Lua, extHost)
|
luaHost, err := luahost.New(conf.Lua, extHost)
|
||||||
if err != nil {
|
if err != nil && err != luahost.ErrNoScript {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user