dataform-co / dataform-web-tracking

Dataform is a collaborative data modelling platform that enables analysts and engineers to manage complex data models in SQL
https://dataform.co
MIT License
2 stars 0 forks source link

Compilation errors for JavaScript is not useful #317

Closed frans-snyders closed 11 months ago

frans-snyders commented 2 years ago

When developing in Javascript in Dataform, many times the error is "Compilation errors: Error: Cannot read property 'name' of undefined".

The error is generic and does not specify what file or what line of code is the problem. Something simple like having an extra comma in a JSON constant causes the error. Debugging this error means disabling code blocks, and re-activating them until the error occurs.

The error also does not come up until the JS file is surfaced ... so you can code in multiple files, and not receive and error, and then once you import the JS file into the root includes folder, then the error appears.

Suggestion: Add more detail on where the error occurred, and the context.

BenBirt commented 2 years ago

Thanks for this bug.

Would you mind posting some example broken code? That would help us identify the case(s) that we can try to identify / report better errors for.

Also, are you using the latest version of @dataform/core? It has upgraded support for reporting such errors.

frans-snyders commented 2 years ago

I believer we are on the latest core: "@dataform/core": "1.19.0"

A) replicate non-error that should error

  1. create a subfolder in includes
  2. paste below code in JS in subfolder
    
    const SAIL = [1,2];

SAILS.forEach((view_item) => {});


This should error, because SAILS is not defined ... but somehow dataform only resolves/check JS in the includes root folder

only oncce the above JS is imported to the root via require() then the error shows up

B) I'll try replicate the "Cannot read property 'name' of undefined" error and post here
frans-snyders commented 2 years ago

B) I tried to replicate the error ... but it seems that once copy the code to a new JS file, then the error system working again ... but just for the new file.

Screenshot of error in main code (includes/lkml_generate/_lkml_view): image

Screenshot of error given for main code: image

...

Copy-pasting the faulty code (all code in the JS file) into a different JS file, with the same path structure(includes/lkml_generate/test_2): image

image

... so it seems like it's a dataform issue for resolving the error ... somehow making a new file re-initialises everything and then it detects the error.

PS. going back and "breaking" the original code after seeing the error in the copied code - results in the same "Cannot read property 'name' of undefined" error for the original code ... so somehow it's the fil/state itself

PPS. the "workaround" does not work for all cases...

BenBirt commented 2 years ago

I think the behaviour you're seeing here are artifacts of the way that Dataform and/or JavaScript "validate" code.

1) we won't through a compile error for invalid JavaScript until that JavaScript is actually executed - this is just the way that JavaScript (or any scripting language) works 2) a JS file will only be executed if (a) it is require()d, or (b) it is in the top level includes directory, which Dataform automatically requires for all other code to use easily

frans-snyders commented 2 years ago

@BenBirt - yes, that explains case A ... All code should be in require() if not in the root includes directory

Case B is still an issue.

Maybe it's possible to add a JS "OUTLINE" debug panel when editing JS - where the current JS file can be run ? and maybe add a console.log() function ;)

PS screen capture of case B https://ufile.io/9i629ilh (expires in 30 days)

BenBirt commented 2 years ago

Are you sure that case B isn't just happening because one of the files is required by other code (and thus executed), and the other file is not?

If you are sure that this isn't what's happening, if you have a simple reproduction case, that would be helpful.

frans-snyders commented 2 years ago

Hi, as per screen capture it's not because of the required use... When trying to re-product the error, then the error-handling works for the newly pasted code - exact same code, just a different file name.

I'll keep trying to reproduce the error and see if some code results directly to the error "Cannot read property 'name' of undefined"