diff --git a/lib/ios.js b/lib/ios.js index 85c7ba7..18448b0 100644 --- a/lib/ios.js +++ b/lib/ios.js @@ -5,9 +5,21 @@ const path = require('path'); const logger = require('./common/logger'); const XCTest = require('xctest-client'); const Simulator = require('ios-simulator'); +const pkg = require('../package.json'); +const chalk = require('chalk'); const _ = require('./common/helper'); +function reportNodesError(source) { + return chalk.red( + `The source may be wrong, please report with below message at: + ${chalk.blue(pkg.bugs)} + ****** xctest source start ******* + ${JSON.stringify(JSON.parse(source))} + '****** xctest source end *******` + ); +} + const adaptor = function(node) { node.class = node.type; @@ -44,8 +56,16 @@ exports.dumpXMLAndScreenShot = function *() { _.mkdir(tempDir); const xmlFilePath = path.join(tempDir, 'ios.json'); + let compatibleTree; + try { + compatibleTree = adaptor(tree); + } catch(e) { + console.error(reportNodesError(source)); + throw e; + } + + fs.writeFileSync(xmlFilePath, JSON.stringify(compatibleTree), 'utf8'); logger.debug(`Dump iOS XML success, save to ${xmlFilePath}`); - fs.writeFileSync(xmlFilePath, JSON.stringify(adaptor(tree)), 'utf8'); const screenshot = yield _.request(`http://${xctest.proxyHost}:${xctest.proxyPort}/screenshot`, 'get', {}); const base64Data = JSON.parse(screenshot).value; diff --git a/package.json b/package.json index 4da4769..8f2018d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app-inspector", - "version": "1.2.8", + "version": "1.2.9", "description": "app inspector", "keywords": [ "inspector", @@ -64,6 +64,7 @@ "jshint" ], "homepage": "https://github.com/macacajs/app-inspector", + "bugs": "https://github.com/macacajs/app-inspector/issues/new", "license": "MIT", "optionalDependencies": { "ios-simulator": "^1.0.7",