Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: Report error positions against a sourcemap #230

Open
josephjclark opened this issue Apr 26, 2023 · 3 comments · May be fixed by #848
Open

Runtime: Report error positions against a sourcemap #230

josephjclark opened this issue Apr 26, 2023 · 3 comments · May be fixed by #848
Assignees

Comments

@josephjclark
Copy link
Collaborator

I don't think this will be easy, but it should be possible. And it's not tracked here, so:

When an expression throws, we should report an error against its sourcemapped source, refering to the line and column number, job name, and if appropriate the file name.

This is a bit tricky right now because errors are reported from the the VM inside SourceTextModule. I'm deliberately hiding stacktrace information because what we get for free is at best useless, at worst confusing.

The reported position has to refer back to the uncompiled code - although this may give us a problem if the error is in the compiled stuff (like import {fn }).

@josephjclark josephjclark changed the title Runtime: Report errors positions against a sourcemap Runtime: Report error positions against a sourcemap Apr 27, 2023
@stuartc
Copy link
Member

stuartc commented May 4, 2023

Check out magic-string as a potential tool for generating source maps iteratively https://www.npmjs.com/package/magic-string

@taylordowns2000 taylordowns2000 moved this to Icebox in v2 Feb 3, 2024
@josephjclark josephjclark self-assigned this Nov 22, 2024
@doc-han
Copy link
Collaborator

doc-han commented Nov 23, 2024

I'm having some silly idea of generating an inline source map after the compiler transformation and adding that to the final code that's going to be executed by the vm(mostly).

I currently don't know whether the inline source map will be considered when an error is thrown

It seems the major difference between source code and compiled code is some additional code that wraps it. Hence we should be able to map the lines I guess.
eg. source

fn(state=> state)
fn(state=> {
  state.data.smth = "smth"
  return state;
})

eg. compiled

import {fn} from "@openfn/common"

export default [
fn(state=> state),
fn(state=> {
  state.data.smth = "smth"
  return state;
})
]

mostly the entire source code just sits in the array.

Just some random thought.

@josephjclark
Copy link
Collaborator Author

Hi @doc-han - I'm actually half way through this story. We get a source mapping solution out-of-the-box with recast - it's just about applying it in the right places in the code.

I've got a prioritised work list for you with plenty of interesting compiler and runtime stuff, and we've got a couple of bigger projects planned too. Hang tight and we'll keep you busy!

@josephjclark josephjclark linked a pull request Dec 19, 2024 that will close this issue
20 tasks
@josephjclark josephjclark moved this from Icebox to In review in v2 Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging a pull request may close this issue.

3 participants