1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

luahost: use sentinel ErrNoScript (#490)

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-02-16 14:16:17 -08:00
committed by GitHub
parent 8adae023dc
commit def3e88651
2 changed files with 6 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package luahost
import (
"bufio"
"errors"
"fmt"
"io"
"os"
@@ -15,6 +16,9 @@ import (
"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.
type Host struct {
extHost *extension.Host
@@ -35,7 +39,7 @@ func New(conf config.Lua, extHost *extension.Host) (*Host, error) {
// Pre-load, parse, and compile script.
if fi, err := os.Stat(scriptPath); err != nil {
logger.Info().Msg("Script file not found")
return nil, nil
return nil, ErrNoScript
} else if fi.IsDir() {
return nil, fmt.Errorf("lua script %v is a directory", scriptPath)
}