Skip to content

[Bug]: 当插件使用了import语句且代码存在问题时将抛出意外的错误输出 #342

@xinchenxpc

Description

@xinchenxpc

Describe the bug

插件使用了import语句且代码存在问题时将抛出意外的错误输出
例如:

14:31:43.807 ERROR [LeviLamina] 无法加载 issues
14:31:43.807 ERROR [LeviLamina] Failed to load plugin issues: Unexpected token '{'
14:31:43.807 ERROR [LeviLamina]     at ./plugins/issues\index.js:1:1

To Reproduce

./plugins/issuse创建具有以下结构的插件,如图:
Image
其中index.js

import { something } from "./plugins/issues/file.js";

log(a)

file.js

function something() {
  return "out";
}

export { something };

manifest.json

{
    "entry": "index.js",
    "name": "issues",
    "type": "lse-quickjs",
    "version": "1.0.0",
    "dependencies": [
        {
            "name": "legacy-script-engine-quickjs"
        }
    ]
}

可以看到,index.js中使用了未定义的变量a,当插件被加载时便会抛出bug描述中的错误

同样地,当错误不在入口文件时,把file.js改为:

function something() {
  return a;
}

export { something };

index.js改为:

import { something } from "./plugins/issues/file.js";

log(something());

仍然抛出相同的错误:

15:03:06.785 ERROR [Server] Failed to reload mod issues
15:03:06.785 ERROR [Server] Failed to load plugin issues: Unexpected token '{'
15:03:06.785 ERROR [Server]     at ./plugins/issues\index.js:1:1

可以看到,甚至连发生错误的位置还仍然指向index.js

Expected behavior

抛出正确的错误:

14:55:07.629 ERROR [Server] Failed to load mod issues
14:55:07.629 ERROR [Server] Failed to load plugin issues: a is not defined
14:55:07.629 ERROR [Server]     at <eval> (./plugins/issues\index.js:3:1)

Screenshots

No response

Platform

windows server 2022

BDS Version

1.21.124-2

LeviLamina Version

1.7.7

LegacyScriptEngine Version

v0.16.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions