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

column property from error messages is non-enumerable in 4.0.6 with noEscape: true (breaking regression) #1284

Closed
nathanboktae opened this issue Dec 19, 2016 · 11 comments · Fixed by renovatebot/renovate#194

Comments

@nathanboktae
Copy link

We had a test that tried to compile this simple template and verify the error result:

SELECT sum(gold_balance) FROM {{#if}}_p_user__gold_balance{{/foo}}
{
  "column": 33,
  "lineNumber": 1,
  "message": "if doesn't match foo - 1:33",
  "name": "Error"
}

but it started failing on 4.0.6. Rolling back to 4.0.5 solves it.

~/work/api-server 23bc2a8|merge-dashboard-queries  ✹
 9:12AM 1 ᐅ npm install
api-server@0.0.1 /Users/nblack/work/api-server
└─┬ handlebars@4.0.6
  └── uglify-js@2.7.5

~/work/api-server 23bc2a8|merge-dashboard-queries  ✹
 9:13AM ᐅ TZ=Etc/UTC mocha -g "templated query fails"

  Queries
    Dashboard Queries
      1) should return 400 if the templated query fails to compile


  0 passing (254ms)
  1 failing

  1) Queries Dashboard Queries should return 400 if the templated query fails to compile:

      Error: expected { errors:
   { query:
      { column: 33,
        lineNumber: 1,
        message: 'if doesn\'t match foo - 1:33',
        name: 'Error' } } } response body, got { errors:
   { query:
      { lineNumber: 1,
        message: 'if doesn\'t match foo - 1:33',
        name: 'Error' } } }
      + expected - actual

       {
         "errors": {
           "query": {
      +      "column": 33
             "lineNumber": 1
             "message": "if doesn't match foo - 1:33"
             "name": "Error"
           }

      at endReadableNT (_stream_readable.js:926:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickDomainCallback (internal/process/next_tick.js:122:9)




~/work/api-server 23bc2a8|merge-dashboard-queries  ✹
 9:13AM 1 ᐅ npm install
api-server@0.0.1 /Users/nblack/work/api-server
└── handlebars@4.0.5

~/work/api-server 23bc2a8|merge-dashboard-queries  ✹
 9:14AM ᐅ TZ=Etc/UTC mocha -g "templated query fails"

  Queries
    Dashboard Queries
      ✓ should return 400 if the templated query fails to compile


  1 passing (212ms)
@nathanboktae
Copy link
Author

I know that... Read the subject like one more time. I'm talking about error message shape. The column of the error is missing.

nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 20, 2016
@nknapp
Copy link
Collaborator

nknapp commented Dec 20, 2016

The part I don't fully understand right now is the following. I have done tests with 4.0.5 and 4.0.6 and the following program:

try {
    require('handlebars').compile('abc{{#abd}}aasds{{/ab}}')({abc: 'test'});
} catch (e) {
    console.log('1) ', JSON.parse(JSON.stringify(e)))
    console.log('2) ', {lineNumber: e.lineNumber, column: e.column});
}

The column-properties is missing in the stringified output of the exception in 4.0.6, but it is there when accessed directly

Output with Handlebars@4.0.5

1)  { lineNumber: 1,  message: 'abd doesn\'t match ab - 1:6',  name: 'Error',  column: 6 }
2)  { lineNumber: 1, column: 6 }

Output with Handlebars@4.0.6

1)  { lineNumber: 1,message: 'abd doesn\'t match ab - 1:6',   name: 'Error' }
2)  { lineNumber: 1, column: 6 }

@nathanboktae
Copy link
Author

nathanboktae commented Dec 20, 2016

Ah yes, I tried it and see your results @nknapp, but I am using the noEscape option and it repros with that:

try {
    require('handlebars').compile('abc{{#abd}}aasds{{/ab}}', { noEscape: true })({abc: 'test'});
} catch (e) {
    console.log('1) ', JSON.parse(JSON.stringify(e)))
    console.log('2) ', {lineNumber: e.lineNumber, column: e.column});
}

Output with Handlebars@4.0.5

1)  { lineNumber: 1,
  message: 'abd doesn\'t match ab - 1:6',
  name: 'Error',
  column: 6 }
2)  { lineNumber: 1, column: 6 }

Output with Handlebars@4.0.6

1)  { lineNumber: 1,
  message: 'abd doesn\'t match ab - 1:6',
  name: 'Error' }
2)  { lineNumber: 1, column: 6 }

Somehow that property is not enumerable:

4.0.5

{ value: 6, writable: true, enumerable: true, configurable: true }

4.0.6

{ value: 6, writable: false, enumerable: false, configurable: false }

@nathanboktae nathanboktae changed the title Column omitted from error messages in 4.0.6 (breaking regression) column property from error messages is non-enumerable in 4.0.6 (breaking regression) Dec 20, 2016
@nathanboktae nathanboktae changed the title column property from error messages is non-enumerable in 4.0.6 (breaking regression) column property from error messages is non-enumerable in 4.0.6 with noEscape: true (breaking regression) Dec 20, 2016
@nknapp
Copy link
Collaborator

nknapp commented Dec 21, 2016

I believe this is due to 20c965c. I have updated #1285 to make the column-property enumerable. It would be interesting to know, if this really solves your problem.

@nathanboktae
Copy link
Author

if this really solves your problem

Oh yes it does. Object.defineProperty defaults enumerable to false, so it doesn't get JSON serialized out. (I tested it as well).

Thanks for the timely response!

@nknapp
Copy link
Collaborator

nknapp commented Dec 22, 2016 via email

nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 22, 2016
Related to handlebars-lang#1284

The test ensures that the property is there, because it is important to
some people.
nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 22, 2016
Fixes handlebars-lang#1284

Appearently, there is a use-case of stringifying the error in order to
evaluated its properties on another system. There was a regression
from 4.0.5  to 4.0.6 that the column-property of compilation errors
was not  enumerable anymore in 4.0.6 (due to  commit 20c965c) and
thus was not included in the output of "JSON.stringify".
@kpdecker
Copy link
Collaborator

@nknapp odds are I never reporduced that myself, just applied the bug fix referenced in the commit message and hoped that reduced the occurrences. Bugs like that, all you can really do is release it and hope it doesn't fuck up. (You'll find that with Handlebars, someone will be pissed for some reason for every change, so embrace it)

@nathanboktae
Copy link
Author

Bugs like that, all you can really do is release it and hope it doesn't fuck up. (You'll find that with Handlebars, someone will be pissed for some reason for every change, so embrace it)

Uh the big stems from not knowing how Object.definePropery and ES5 properties work. Basic understanding of JavaScript IMO. Not pointing fingers, I understand the hard work it takes to maintain open source JavaScript as I do myself, but that isn't the right attitude to take here. Anyways thank you looking g forward to the fix.

@kpdecker
Copy link
Collaborator

kpdecker commented Dec 28, 2016

@nathanboktae the concern was that the change would cause a browser crasher, which any amount of knowledge of javascript isn't going to help as they don't really spec out "the browser will crash at this point"

It's comments like these highlight why I'm no longer maintaining this project. After years of dealing with open source users at this large of a scale, for free mind you, I no longer am inclined to do the dirty work. If you don't like my attitude at this point, I suggest you invest your time in another project or spend timing maintaining the issues here.

nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 29, 2016
Related to handlebars-lang#1284

The test ensures that the property is there, because it is important to
some people.
nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 29, 2016
Fixes handlebars-lang#1284

Appearently, there is a use-case of stringifying the error in order to
evaluated its properties on another system. There was a regression
from 4.0.5  to 4.0.6 that the column-property of compilation errors
was not  enumerable anymore in 4.0.6 (due to  commit 20c965c) and
thus was not included in the output of "JSON.stringify".
nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 30, 2016
Related to handlebars-lang#1284

The test ensures that the property is there, because it is important to
some people.
nknapp added a commit to nknapp/handlebars.js that referenced this issue Dec 30, 2016
Fixes handlebars-lang#1284

Appearently, there is a use-case of stringifying the error in order to
evaluated its properties on another system. There was a regression
from 4.0.5  to 4.0.6 that the column-property of compilation errors
was not  enumerable anymore in 4.0.6 (due to  commit 20c965c) and
thus was not included in the output of "JSON.stringify".
nknapp added a commit that referenced this issue Dec 30, 2016
Related to #1284

The test ensures that the property is there, because it is important to
some people.
nknapp added a commit that referenced this issue Dec 30, 2016
Fixes #1284

Appearently, there is a use-case of stringifying the error in order to
evaluated its properties on another system. There was a regression
from 4.0.5  to 4.0.6 that the column-property of compilation errors
was not  enumerable anymore in 4.0.6 (due to  commit 20c965c) and
thus was not included in the output of "JSON.stringify".
@nknapp
Copy link
Collaborator

nknapp commented Dec 30, 2016

The fix is merged into the 4.x-branch and should be published with 4.0.7.
@wycats What is the preferred approach for committing those changes to the master branch? Cherry-pick? Or should I merge 4.x back into master?

@nathanboktae
Copy link
Author

closing since this is merged in. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants