federomero / pretty-json

Atom plugin. Format JSON documents.
MIT License
94 stars 23 forks source link

Uncaught ReferenceError: packageName is not defined #44

Closed dmontagner closed 8 years ago

dmontagner commented 8 years ago

[Enter steps to reproduce below:]

  1. Paste the following text
{u'Name': u'Boot Order Pending Settings', u'links': {u'self': {u'href': u'/rest/v1/systems/1/bios/Boot/Settings'}}, u'Modified': u'2016-06-03T01:38:44+00:00', u'Description': u'This is the Server Boot Order Pending Settings', u'DesiredBootDevices': [{u'Wwn': u'', u'iScsiTargetName': u'', u'Lun': u'', u'CorrelatableID': u''}, {u'Wwn': u'', u'iScsiTargetName': u'', u'Lun': u'', u'CorrelatableID': u''}], u'PersistentBootConfigOrder': [u'HD.Emb.1.1', u'Generic.USB.1.1', u'NIC.LOM.1.1.IPv4', u'NIC.LOM.1.1.IPv4', u'NIC.LOM.1.1.IPv6', u'NIC.FlexLOM.1.1.IPv6', u'NIC.Slot.2.1.IPv4', u'NIC.Slot.3.1.IPv4', u'NIC.Slot.2.1.IPv6', u'NIC.Slot.3.1.IPv6'], u'Type': u'HpServerBootSettings.1.2.0', u'DefaultBootOrder': [u'Floppy', u'Cd', u'Usb', u'EmbeddedStorage', u'PcieSlotStorage', u'EmbeddedFlexLOM', u'PcieSlotNic', u'UefiShell']}
  1. Click on "Pretty JSON/JSNONify JavsScript Object Literal and Sort and Prettify

Atom Version: 1.7.4 System: Mac OS X 10.11.5 Thrown From: pretty-json package, v1.4.0

Stack Trace

Uncaught ReferenceError: packageName is not defined

At /Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:833

ReferenceError: packageName is not defined
    at Object.formatter.jsonify (/Users/dmontagner/.atom/packages/pretty-json/index.coffee:53:40)
    at /Users/dmontagner/.atom/packages/pretty-json/index.coffee:96:48
    at /Users/dmontagner/.atom/packages/pretty-json/index.coffee:77:36
    at /Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:874:29
    at TextBuffer.module.exports.TextBuffer.transact (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:828:18)
    at TextEditor.module.exports.TextEditor.transact (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:1274:26)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:868:24
    at TextEditor.module.exports.TextEditor.mergeSelections (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:2170:18)
    at TextEditor.module.exports.TextEditor.mergeIntersectingSelections (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:2132:35)
    at TextEditor.module.exports.TextEditor.mutateSelectedText (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:866:19)
    at Object.PrettyJSON.replaceText (/Users/dmontagner/.atom/packages/pretty-json/index.coffee:73:12)
    at Object.PrettyJSON.jsonify (/Users/dmontagner/.atom/packages/pretty-json/index.coffee:96:8)
    at atom-workspace.atom.commands.add.pretty-json:jsonify-literal-and-sort-and-prettify (/Users/dmontagner/.atom/packages/pretty-json/index.coffee:114:10)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61)
    at CommandRegistry.module.exports.CommandRegistry.dispatch (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:160:19)
    at AtomEnvironment.module.exports.AtomEnvironment.dispatchApplicationMenuCommand (/Applications/Atom.app/Contents/Resources/app.asar/src/atom-environment.js:1100:28)
    at EventEmitter.outerCallback (/Applications/Atom.app/Contents/Resources/app.asar/src/application-delegate.js:314:25)
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:172:7)

Commands

     -0:14 editor:move-to-first-character-of-line (atom-text-editor.editor.is-focused)
     -0:12.8.0 core:select-all (atom-text-editor.editor.is-focused)
     -0:08.0 pretty-json:prettify (atom-text-editor.editor.is-focused)
     -0:00.7.0 pretty-json:jsonify-literal-and-sort-and-prettify (atom-text-editor.editor.is-focused)

Config

{
  "core": {}
}

Installed Packages

# User
Remote-FTP, v0.8.3
pretty-json, v1.4.0
remote-edit, v1.8.24

# Dev
No dev packages
lexicalunit commented 8 years ago

Sorry for the inconvenience. I've discovered the bug, fixed it, and am working on creating a new patch release asap.

lexicalunit commented 8 years ago

@dmontagner v1.4.1 has just been published and it should resolve this issue.

lexicalunit commented 8 years ago

@dmontagner You will still get a warning with the code you posted in this issue, however. It doesn't seem that u'...' is a valid JavaScript string literal. So you will get a syntax error warning indicating an unexpected string.

If you remove all the u prefixes from the strings in your code and run Pretty JSON/JSNONify JavsScript Object Literal and Sort and Prettify, you should get the following output:

{
    "DefaultBootOrder": [
        "Floppy",
        "Cd",
        "Usb",
        "EmbeddedStorage",
        "PcieSlotStorage",
        "EmbeddedFlexLOM",
        "PcieSlotNic",
        "UefiShell"
    ],
    "Description": "This is the Server Boot Order Pending Settings",
    "DesiredBootDevices": [
        {
            "CorrelatableID": "",
            "Lun": "",
            "Wwn": "",
            "iScsiTargetName": ""
        },
        {
            "CorrelatableID": "",
            "Lun": "",
            "Wwn": "",
            "iScsiTargetName": ""
        }
    ],
    "Modified": "2016-06-03T01:38:44+00:00",
    "Name": "Boot Order Pending Settings",
    "PersistentBootConfigOrder": [
        "HD.Emb.1.1",
        "Generic.USB.1.1",
        "NIC.LOM.1.1.IPv4",
        "NIC.LOM.1.1.IPv4",
        "NIC.LOM.1.1.IPv6",
        "NIC.FlexLOM.1.1.IPv6",
        "NIC.Slot.2.1.IPv4",
        "NIC.Slot.3.1.IPv4",
        "NIC.Slot.2.1.IPv6",
        "NIC.Slot.3.1.IPv6"
    ],
    "Type": "HpServerBootSettings.1.2.0",
    "links": {
        "self": {
            "href": "/rest/v1/systems/1/bios/Boot/Settings"
        }
    }
}
dmontagner commented 8 years ago

Hi Amy,

So, whenever we enter an invalid string for this particular plugin, will we always get the warning/exception ?

Just wondering if instead we could get an error message saying the string is not valid for that particular plugin.

Thanks

Sent from my iPhone

On 4 Jun 2016, at 01:58, Amy Troschinetz notifications@github.com<mailto:notifications@github.com> wrote:

@dmontagnerhttps://github.com/dmontagner You will still get a warning with the code you posted in this issue, however. It doesn't seem that u'...' is a valid JavaScript string literalhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#String_literals. So you will get a syntax error warning indicating an unexpected string.

If you remove all the u prefixes from the strings in your code and run Pretty JSON/JSNONify JavsScript Object Literal and Sort and Prettify, you should get the following output:

{ "DefaultBootOrder": [ "Floppy", "Cd", "Usb", "EmbeddedStorage", "PcieSlotStorage", "EmbeddedFlexLOM", "PcieSlotNic", "UefiShell" ], "Description": "This is the Server Boot Order Pending Settings", "DesiredBootDevices": [ { "CorrelatableID": "", "Lun": "", "Wwn": "", "iScsiTargetName": "" }, { "CorrelatableID": "", "Lun": "", "Wwn": "", "iScsiTargetName": "" } ], "Modified": "2016-06-03T01:38:44+00:00", "Name": "Boot Order Pending Settings", "PersistentBootConfigOrder": [ "HD.Emb.1.1", "Generic.USB.1.1", "NIC.LOM.1.1.IPv4", "NIC.LOM.1.1.IPv4", "NIC.LOM.1.1.IPv6", "NIC.FlexLOM.1.1.IPv6", "NIC.Slot.2.1.IPv4", "NIC.Slot.3.1.IPv4", "NIC.Slot.2.1.IPv6", "NIC.Slot.3.1.IPv6" ], "Type": "HpServerBootSettings.1.2.0", "links": { "self": { "href": "/rest/v1/systems/1/bios/Boot/Settings" } } }

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/federomero/pretty-json/issues/44#issuecomment-223619109, or mute the threadhttps://github.com/notifications/unsubscribe/AEtR2qyUxRsxdbvLUDX8PwKR5rf_-4E-ks5qIE88gaJpZM4ItKcS.

lexicalunit commented 8 years ago

@dmontagner if there's a JSON parsing error or a JavaScript syntax error then pretty-json will try to be helpful by letting the user see that error message. Sadly the syntax errors for JavaScript are, imho, particularly bad.