sterpe / coffee-fmt

gofmt for coffee
MIT License
9 stars 4 forks source link

Cannot read property 'toString' of null #17

Open Glavin001 opened 9 years ago

Glavin001 commented 9 years ago

For file: https://github.com/Glavin001/atom-beautify/blob/6b7b3d6401219d3fb491026062cced167042fe1b/src/beautify.coffee

TypeError: Cannot read property 'toString' of null
  at Object.exports.flag (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/coffee-fmt/frontend/coffeescript/CoffeeErrorHandler.js:28:15)
  at Object.parse (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/coffee-fmt/frontend/coffeescript/CoffeeParserTD.js:40:17)
  at Object.exports.format (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/coffee-fmt/Coffeescript.js:137:10)
  at module.exports.CoffeeFmt.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/coffee-fmt.coffee:27:23)
  at tryCatcher (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/util.js:24:31)
  at Promise.module.exports.Promise._resolveFromResolver (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:427:31)
  at new Promise (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:53:37)
  at CoffeeFmt.module.exports.CoffeeFmt.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/coffee-fmt.coffee:20:16)
  at module.exports.Beautifiers.beautify (/Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/index.coffee:442:24)
  at tryCatcher (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/util.js:24:31)
  at Promise.module.exports.Promise._resolveFromResolver (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:427:31)
  at new Promise (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:53:37)
  at /Users/glavin/Documents/Project Dev/atom-beautify/src/beautifiers/index.coffee:314:18
  at tryCatcher (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/util.js:24:31)
  at Promise.module.exports.Promise._settlePromiseFromHandler (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:454:31)
  at Promise.module.exports.Promise._settlePromiseAt (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:530:18)
  at Promise.module.exports.Promise._settlePromises (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/promise.js:646:14)
  at Async._drainQueue (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/async.js:177:16)
  at Async._drainQueues (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/async.js:187:10)
  at MutationObserver.drainQueues (/Users/glavin/Documents/Project Dev/atom-beautify/node_modules/bluebird/js/main/async.js:15:14)
Glavin001 commented 9 years ago

I think I have narrowed it down to:


debug = () ->

    # Get current editor
    editor = atom.workspace.getActiveTextEditor()

    # Check if there is an active editor
    if not editor?
        return confirm("Active Editor not found.\n" +
        "Please select a Text Editor first to beautify.")
    return unless confirm('Are you ready to debug Atom Beautify?\n\n' +
    'Warning: This will change your current clipboard contents.')
    debugInfo = ""
    addInfo = (key, val) ->
        debugInfo += "**#{key}**: #{val}\n\n"
    addHeader = (level, title) ->
        debugInfo += "#{Array(level+1).join('#')} #{title}\n\n"
    addHeader(1, "Atom Beautify - Debugging information")
    debugInfo += "The following debugging information was " +
    "generated by `Atom Beautify` on `#{new Date()}`." +
    "\n\n---\n\n"

    # Platform
    addInfo('Platform', process.platform)
    addHeader(2, "Versions")

    # Atom Version
    addInfo('Atom Version', atom.appVersion)

    # Atom Beautify Version
    addInfo('Atom Beautify Version', pkg.version)
    addHeader(2, "Original file to be beautified")

    # Original file
    #
    # Get editor path and configurations for paths
    filePath = editor.getPath()

    # Path
    addInfo('Original File Path', "`#{filePath}`")

    # Get Grammar
    grammarName = editor.getGrammar().name

    # Grammar
    addInfo('Original File Grammar', grammarName)

    # Get current editor's text
    text = editor.getText()

    # Contents
    codeBlockSyntax = grammarName.toLowerCase().split(' ')[0]
    addInfo('Original File Contents', "\n```#{codeBlockSyntax}\n#{text}\n```")
    addHeader(2, "Beautification options")

    # Beautification Options
    # Get all options
    allOptions = beautifier.getOptionsForPath(filePath, editor)
    # Resolve options with promises
    Promise.all(allOptions)
    .then((allOptions) =>
        # Extract options
        [
            editorOptions
            configOptions
            homeOptions
            editorConfigOptions
        ] = allOptions
        projectOptions = allOptions[4..]

        # Show options
        addInfo('Editor Options', "\n" +
        "Options from Atom Editor settings\n" +
        "```json\n#{JSON.stringify(editorOptions, undefined, 4)}\n```")
        addInfo('Config Options', "\n" +
        "Options from Atom Beautify package settings\n" +
        "```json\n#{JSON.stringify(configOptions, undefined, 4)}\n```")
        addInfo('Home Options', "\n" +
        "Options from `#{path.resolve(beautifier.getUserHome(), '.jsbeautifyrc')}`\n" +
        "```json\n#{JSON.stringify(homeOptions, undefined, 4)}\n```")
        addInfo('EditorConfig Options', "\n" +
        "Options from [EditorConfig](http://editorconfig.org/) file\n" +
        "```json\n#{JSON.stringify(editorConfigOptions, undefined, 4)}\n```")
        addInfo('Project Options', "\n" +
        "Options from `.jsbeautifyrc` files starting from directory `#{path.dirname(filePath)}` and going up to root\n" +
        "```json\n#{JSON.stringify(projectOptions, undefined, 4)}\n```")
        logs = ""
        subscription = logger.onLogging((msg) ->

            # console.log('logging', msg)
            logs += msg
        )
        cb = (result) ->
            subscription.dispose()
            addHeader(2, "Results")

            # Logs
            addInfo('Beautified File Contents', "\n```#{codeBlockSyntax}\n#{result}\n```")
            addInfo('Logs', "\n```\n#{logs}\n```")

            # Save to clipboard
            atom.clipboard.write(debugInfo)
            confirm('Atom Beautify debugging information is now in your clipboard.\n' +
            'You can now paste this into an Issue you are reporting here\n' +
            'https://github.com/Glavin001/atom-beautify/issues/ \n\n' +
            'Warning: Be sure to look over the debug info before you send it,
            to ensure you are not sharing undesirable private information.'
            )
        try
            beautifier.beautify(text, allOptions, grammarName, filePath)
            .then(cb)
            .catch(cb)
        catch e
            return cb(e)
    )
sterpe commented 9 years ago

Maybe this line:

    projectOptions = allOptions[4..]

The range, don't think I handle that.

xgdgsc commented 8 years ago

I get this error too with so basic range: [1..5].

sterpe commented 8 years ago

Yeah, I forgot to support ranges.

ldez commented 7 years ago

Can you explain the line, I don't understand the meaning.

sterpe commented 7 years ago

So, I think because I forgot about the range operator, I still needed to get three ellipses 'operator' ... but forgetting about the range operator, as I did (because I don't actually use coffeescript much), I treated .. as an error, but I needed it in order for the boolean statement above it to be true to process onto the ... ... If you are fixing ranges support you can probably just get rid of that forced error so long as we deal with the fact that a range can only be declared under certain circumstances.

lkytal commented 7 years ago

Any available solution?