Comments (2)
You can't get it from the error itself, because it's a value, not type, but you can get the location from the stacktrace, which will point to the line of code that contains the require
. If you are doing something like dynamic require, you can write a wrapper function.
from goja_nodejs.
maybe someone can use it in the future!
func formatGojaErr(script string, err error) error {
ex, ok := err.(*goja.Exception)
if ok {
if strings.Contains(ex.String(), "Invalid module") {
stackframes := strings.Split(ex.String(), "\n")
if len(stackframes) > 2 {
lines := strings.Split(stackframes[2], ":")
if len(lines) > 2 {
line, err := strconv.Atoi(lines[1])
if err == nil {
errLine := strings.Split(script, "\r\n")[line-1]
if strings.Contains(errLine, "require") {
re := regexp.MustCompile(`['"]([^'"]+)['"]`)
match := re.FindStringSubmatch(errLine)
if len(match) > 0 {
return errors.New("Invalid module: " + match[1])
}
}
}
}
}
}
}
return err
}
from goja_nodejs.
Related Issues (20)
- could you help me understand the example on README HOT 1
- Docs Request
- [Feature]: Support Path module
- how to return valuein eventloop? HOT 1
- join contribution
- Is there any plan to implement http
- EventLoop : Wait for all jobs to finish HOT 7
- [Feature Request] Add a option for disable the `require` method when using EventLoop HOT 1
- setInterval setImmediate HOT 3
- EventLoop: runtime management
- evenloop.Run hang with setInterval HOT 3
- Event loop gets stuck unexpectedly HOT 1
- GoError: Invalid module at github.com/dop251/goja_nodejs/require.(*RequireModule).require-fm (native) HOT 1
- Can native crypto packages be supported? HOT 2
- Fatal Error: Concurrent Map Writes
- require need add current runtime's parser options HOT 4
- Use ada-url for url implementation HOT 1
- Resolving promises causes deadlock if the eventloop is stopped HOT 1
- Event loop leaks intervals HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goja_nodejs.