Electronic error while canceling file open dialog

When I click the cancel button in the file open dialog box (code below), I get the following error:

A JavaScript error occurred in the main process

Uncaught Exception:
TypeError: Error processing argument -1.
    at TypeError (native)
    at [object Object].Object.defineProperty.set (/Applications/Electron.app/Contents/Resources/atom.asar/browser/api/lib/web-contents.js:92:24)
    at main.js:37:20
    at Function.wrappedCallback (/Applications/Electron.app/Contents/Resources/atom.asar/browser/api/lib/dialog.js:80:16)

The error is presented as a modal popup:

Error popup

I have tested only on Mac so far.

My code is as follows:

The main code for the process that handles the creation of the dialog box is as follows:

import electron, { ipcMain } from 'electron'

const app = electron.app
const BrowserWindow = electron.BrowserWindow

electron.crashReporter.start()

let mainWindow = null

app.on('window-all-closed', () => {
  if (process.platform != 'darwin') app.quit()
})

app.on('ready', () => {

  mainWindow = new BrowserWindow({
    width: 800,
    height: 600
  })

  mainWindow.loadURL(`file://${__dirname}/index.html`)
  mainWindow.webContents.openDevTools()

  mainWindow.on('closed', () => {
    mainWindow = null
  })

  ipcMain.on('file:open', (e, arg) => {
    electron.dialog.showOpenDialog(mainWindow, {
      properties: ['openFile'],
      filters: [{
        name: 'Outlines',
        extensions: ['pxo']
      }]
    }, (filePathList) => {
      debugger
      e.returnValue = filePathList
    })
  })

})

My debugger instruction has never been reached. In addition, the code works fine when some files are actually selected, and only crashes when you click cancel.

The code (ES6 + JSX) causing the IPC call is as follows:

class Welcome extends React.Component {

  render() {
    const styles = this.getStyles()

    return (
      <div style={styles.outerContainer}>
              <a style={styles.btnSetLink} onClick={this.initFileSelection.bind(this)}>
                Open File
              </a>
      </div>
    )
  }

  initFileSelection() {
    const filePathList = ipcRenderer.sendSync('file:open')
  }

  ...

The code is processed through babel 6. Mine .babelrclooks like this:

{
  "presets": ["react", "es2015"]
}

Electronic version: v0.35.1.

Babel dependency versions:

β”œβ”€β”¬ babel-preset-es2015@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-check-es2015-constants@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-arrow-functions@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-block-scoped-functions@6.3.13
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-block-scoping@6.3.13
β”‚ β”‚ β”œβ”€β”¬ babel-template@6.3.13
β”‚ β”‚ β”‚ └── babylon@6.3.18
β”‚ β”‚ β”œβ”€β”¬ babel-traverse@6.3.19
β”‚ β”‚ β”‚ β”œβ”€β”€ babylon@6.3.18
β”‚ β”‚ β”‚ β”œβ”€β”€ globals@8.15.0
β”‚ β”‚ β”‚ └─┬ repeating@1.1.3
β”‚ β”‚ β”‚   └─┬ is-finite@1.0.1
β”‚ β”‚ β”‚     └── number-is-nan@1.0.0
β”‚ β”‚ └─┬ babel-types@6.3.18
β”‚ β”‚   β”œβ”€β”€ esutils@2.0.2
β”‚ β”‚   └── to-fast-properties@1.0.1
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-classes@6.3.15
β”‚ β”‚ β”œβ”€β”€ babel-helper-define-map@6.3.13
β”‚ β”‚ β”œβ”€β”€ babel-helper-function-name@6.3.15
β”‚ β”‚ β”œβ”€β”€ babel-helper-optimise-call-expression@6.3.13
β”‚ β”‚ β”œβ”€β”€ babel-helper-replace-supers@6.3.13
β”‚ β”‚ └── babel-messages@6.3.18
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-computed-properties@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-destructuring@6.3.15
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-for-of@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-function-name@6.3.19
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-literals@6.3.13
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-modules-commonjs@6.3.16
β”‚ β”‚ └── babel-plugin-transform-strict-mode@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-object-super@6.3.13
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-parameters@6.3.18
β”‚ β”‚ β”œβ”€β”¬ babel-helper-call-delegate@6.3.13
β”‚ β”‚ β”‚ └── babel-helper-hoist-variables@6.3.13
β”‚ β”‚ └── babel-helper-get-function-arity@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-shorthand-properties@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-spread@6.3.14
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-sticky-regex@6.3.13
β”‚ β”‚ └── babel-helper-regex@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-template-literals@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-es2015-typeof-symbol@6.3.13
β”‚ β”œβ”€β”¬ babel-plugin-transform-es2015-unicode-regex@6.3.13
β”‚ β”‚ └─┬ regexpu@1.3.0
β”‚ β”‚   β”œβ”€β”€ esprima@2.7.1
β”‚ β”‚   β”œβ”€β”¬ recast@0.10.33
β”‚ β”‚   β”‚ β”œβ”€β”€ ast-types@0.8.12
β”‚ β”‚   β”‚ └── esprima-fb@15001.1001.0-dev-harmony-fb
β”‚ β”‚   β”œβ”€β”€ regenerate@1.2.1
β”‚ β”‚   β”œβ”€β”€ regjsgen@0.2.0
β”‚ β”‚   └─┬ regjsparser@0.1.5
β”‚ β”‚     └── jsesc@0.5.0
β”‚ └─┬ babel-plugin-transform-regenerator@6.3.18
β”‚   β”œβ”€β”€ babel-core@6.3.17
β”‚   β”œβ”€β”€ babel-plugin-syntax-async-functions@6.3.13
β”‚   β”œβ”€β”€ babylon@6.3.18
β”‚   └── private@0.1.6
β”œβ”€β”¬ babel-preset-react@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-syntax-flow@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-syntax-jsx@6.3.13
β”‚ β”œβ”€β”€ babel-plugin-transform-flow-strip-types@6.3.15
β”‚ β”œβ”€β”€ babel-plugin-transform-react-display-name@6.3.13
β”‚ β”œβ”€β”¬ babel-plugin-transform-react-jsx@6.3.13
β”‚ β”‚ └── babel-helper-builder-react-jsx@6.3.13
β”‚ └── babel-plugin-transform-react-jsx-source@6.3.13
β”œβ”€β”¬ babel-register@6.3.13
β”‚ β”œβ”€β”¬ babel-core@6.3.17
β”‚ β”‚ β”œβ”€β”¬ babel-code-frame@6.3.13
β”‚ β”‚ β”‚ β”œβ”€β”¬ chalk@1.1.1
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ ansi-styles@2.1.0
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ escape-string-regexp@1.0.3
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ has-ansi@2.0.0
β”‚ β”‚ β”‚ β”‚ β”‚ └── ansi-regex@2.0.0
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ strip-ansi@3.0.0
β”‚ β”‚ β”‚ β”‚ └── supports-color@2.0.0
β”‚ β”‚ β”‚ β”œβ”€β”€ js-tokens@1.0.1
β”‚ β”‚ β”‚ └─┬ line-numbers@0.2.0
β”‚ β”‚ β”‚   └── left-pad@0.0.3
β”‚ β”‚ β”œβ”€β”¬ babel-generator@6.3.19
β”‚ β”‚ β”‚ β”œβ”€β”¬ detect-indent@3.0.1
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ get-stdin@4.0.1
β”‚ β”‚ β”‚ β”‚ └── minimist@1.2.0
β”‚ β”‚ β”‚ β”œβ”€β”€ is-integer@1.0.6
β”‚ β”‚ β”‚ └── trim-right@1.0.1
β”‚ β”‚ β”œβ”€β”€ babel-helpers@6.3.13
β”‚ β”‚ β”œβ”€β”€ babylon@6.3.18
β”‚ β”‚ β”œβ”€β”€ convert-source-map@1.1.2
β”‚ β”‚ β”œβ”€β”¬ debug@2.2.0
β”‚ β”‚ β”‚ └── ms@0.7.1
β”‚ β”‚ β”œβ”€β”€ json5@0.4.0
β”‚ β”‚ β”œβ”€β”¬ minimatch@2.0.10
β”‚ β”‚ β”‚ └─┬ brace-expansion@1.1.2
β”‚ β”‚ β”‚   β”œβ”€β”€ balanced-match@0.3.0
β”‚ β”‚ β”‚   └── concat-map@0.0.1
β”‚ β”‚ β”œβ”€β”€ path-is-absolute@1.0.0
β”‚ β”‚ β”œβ”€β”€ shebang-regex@1.0.0
β”‚ β”‚ β”œβ”€β”€ slash@1.0.0
β”‚ β”‚ └── source-map@0.5.3
β”‚ β”œβ”€β”€ babel-runtime@5.8.34
β”‚ β”œβ”€β”€ core-js@1.2.6
β”‚ β”œβ”€β”¬ home-or-tmp@1.0.0
β”‚ β”‚ β”œβ”€β”€ os-tmpdir@1.0.1
β”‚ β”‚ └── user-home@1.1.1
β”‚ β”œβ”€β”€ lodash@3.10.1
β”‚ β”œβ”€β”€ path-exists@1.0.0
β”‚ └─┬ source-map-support@0.2.10
β”‚   └─┬ source-map@0.1.32
β”‚     └── amdefine@1.0.0

, , .

+4
2

, false ( undefined):

ipc.on 'request:save:dialog', (event, params) ->
  params||={}
  event.returnValue = dialog.showSaveDialog(params) || false
+1

process.on('uncaughtException', function (exception) {
   // handle or ignore error
});
0

Source: https://habr.com/ru/post/1620860/


All Articles