Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Execute js from string and get line number which failed

I am executing js which is stored as a string inside the db via:

let myScript = ` await Some()
lines()
of()
js()`

let result
try{
   result = await Object.getPrototypeOf(async function() {}).constructor(`return (async () => { ${myScript} })()`)()
} catch(e){
   result = 'Error occurred: '+e.message + ' stack: ' + e.stack
}

The problem is: The line numbers of e.stack are not correct. I think it's somehow also counting line numbers of the contextual code. For some js strings, I don't even get a stack.

Anyone knows what the problem is?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to add try-catch block in your string JS, I hope the answer to this Question will help you.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!