Browse Source

Merge pull request #4887 from sergeybekrin/master

Improve error reporting when passing invalid argument types for dialog API methods
Kevin Sawicki 9 years ago
parent
commit
8bcede8019
1 changed files with 16 additions and 2 deletions
  1. 16 2
      lib/browser/api/dialog.js

+ 16 - 2
lib/browser/api/dialog.js

@@ -56,7 +56,7 @@ module.exports = {
       options.properties = ['openFile'];
     }
     if (!Array.isArray(options.properties)) {
-      throw new TypeError('Properties need to be array');
+      throw new TypeError('Properties must be an array');
     }
     properties = 0;
     for (prop in fileDialogProperties) {
@@ -67,9 +67,13 @@ module.exports = {
     }
     if (options.title == null) {
       options.title = '';
+    } else if (typeof options.title !== 'string') {
+      throw new TypeError('Title must be a string');
     }
     if (options.defaultPath == null) {
       options.defaultPath = '';
+    } else if (typeof options.defaultPath !== 'string') {
+      throw new TypeError('Default path must be a string');
     }
     if (options.filters == null) {
       options.filters = [];
@@ -91,9 +95,13 @@ module.exports = {
     }
     if (options.title == null) {
       options.title = '';
+    } else if (typeof options.title !== 'string') {
+      throw new TypeError('Title must be a string');
     }
     if (options.defaultPath == null) {
       options.defaultPath = '';
+    } else if (typeof options.defaultPath !== 'string') {
+      throw new TypeError('Default path must be a string');
     }
     if (options.filters == null) {
       options.filters = [];
@@ -121,16 +129,22 @@ module.exports = {
       throw new TypeError('Invalid message box type');
     }
     if (!Array.isArray(options.buttons)) {
-      throw new TypeError('Buttons need to be array');
+      throw new TypeError('Buttons must be an array');
     }
     if (options.title == null) {
       options.title = '';
+    } else if (typeof options.title !== 'string') {
+      throw new TypeError('Title must be a string');
     }
     if (options.message == null) {
       options.message = '';
+    } else if (typeof options.message !== 'string') {
+      throw new TypeError('Message must be a string');
     }
     if (options.detail == null) {
       options.detail = '';
+    } else if (typeof options.detail !== 'string') {
+      throw new TypeError('Detail must be a string');
     }
     if (options.icon == null) {
       options.icon = null;