From ee7007f0501bce1eb8cd3707d289ea529b4580b9 Mon Sep 17 00:00:00 2001 From: Star Date: Fri, 12 Dec 2025 21:32:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=BD=E6=95=B0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 8 ++++---- response.go | 5 ++++- service.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 0f8c4e8..cd92fc2 100644 --- a/go.mod +++ b/go.mod @@ -46,9 +46,9 @@ require ( github.com/ysmood/gson v0.7.3 // indirect github.com/ysmood/leakless v0.9.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - golang.org/x/crypto v0.44.0 // indirect - golang.org/x/net v0.47.0 // indirect - golang.org/x/sys v0.38.0 // indirect - golang.org/x/text v0.31.0 // indirect + golang.org/x/crypto v0.46.0 // indirect + golang.org/x/net v0.48.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/response.go b/response.go index 6f85ef2..b5d879a 100644 --- a/response.go +++ b/response.go @@ -93,7 +93,10 @@ func (r *Response) Write(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value args := gojs.MakeArgs(&argsIn, vm).Check(1) n, err := r.resp.Write(args.Bytes(0)) if err != nil { - panic(vm.NewGoError(err)) + // panic(vm.NewGoError(err)) + vm.SetData("_lastError", err) + gojs.GetLogger(vm).Error(err.Error()) + return vm.ToValue(false) } return vm.ToValue(n) } diff --git a/service.go b/service.go index 76b116d..b75f631 100644 --- a/service.go +++ b/service.go @@ -260,7 +260,7 @@ func init() { // panic(vm.NewGoError(errors.New("server already started"))) vm.SetData("_lastError", errors.New("server already started")) gojs.GetLogger(vm).Error("server already started") - return nil + return vm.ToValue(false) } // 处理静态文件 if len(serviceConfig.Static) > 0 { @@ -374,11 +374,11 @@ func init() { // panic(vm.NewGoError(errors.New("server not started"))) vm.SetData("_lastError", errors.New("server not started")) gojs.GetLogger(vm).Error("server not started") - return nil + return vm.ToValue(false) } server.Stop() s.ResetAllSets() - return nil + return vm.ToValue(true) }, // "uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { // args := gojs.MakeArgs(&argsIn, vm) @@ -495,7 +495,7 @@ func init() { // panic(vm.NewGoError(errors.New("action must be a callback function"))) vm.SetData("_lastError", errors.New("action must be a callback function")) gojs.GetLogger(vm).Error("action must be a callback function") - return nil + return vm.ToValue(false) } authLevel := o.Int("authLevel") @@ -589,7 +589,7 @@ func init() { // 无对象池,直接调用(单线程) s.RestfulWithOptions(authLevel, method, path, makeInnerAction(action, vm, args.This), memo, opt) } - return nil + return vm.ToValue(true) }, "load": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { args := gojs.MakeArgs(&argsIn, vm).Check(1) @@ -615,14 +615,14 @@ func init() { // panic(vm.NewGoError(errors.New("actionFile must be a js file path: " + fullActionFile))) vm.SetData("_lastError", errors.New("actionFile must be a js file path: "+fullActionFile)) gojs.GetLogger(vm).Error("actionFile must be a js file path: " + fullActionFile) - return nil + return vm.ToValue(false) } actionCode := u.ReadFileN(actionFile) if !strings.Contains(actionCode, "function main(") { // || !strings.Contains(actionCode, ".register(") // panic(vm.NewGoError(errors.New("actionFile must be a js file with main function"))) vm.SetData("_lastError", errors.New("actionFile must be a js file with main function")) gojs.GetLogger(vm).Error("actionFile must be a js file with main function") - return nil + return vm.ToValue(false) } poolsLock.Lock() poolExists[actionFile] = true @@ -646,7 +646,7 @@ func init() { poolsMTime[actionFile] = mtime poolsConfig[actionFile] = poolOpt poolsLock.Unlock() - return nil + return vm.ToValue(true) }, // "task": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { // args := gojs.MakeArgs(&argsIn, vm).Check(1)