From 8b5af354caca9d5d35caa4a3e8566a884945a016 Mon Sep 17 00:00:00 2001 From: Todor Totev Date: Wed, 5 Nov 2014 09:29:33 +0200 Subject: [PATCH] Catch invalid project file and gives an helpful message to the user --- lib/project-data.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/project-data.ts b/lib/project-data.ts index 8b79efe523..638f10823a 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -2,6 +2,7 @@ "use strict"; import path = require("path"); +import os = require("os"); export class ProjectData implements IProjectData { public projectDir: string; @@ -28,8 +29,16 @@ export class ProjectData implements IProjectData { this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME); if (this.$fs.exists(this.projectFilePath).wait()) { + try { var fileContent = this.$fs.readJson(this.projectFilePath).wait(); this.projectId = fileContent.id; + } catch (err) { + this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL + + "Consider restoring an earlier version from your source control or backup." + os.EOL + + "Additional technical info: %s", + suppressCommandHelp: true}, + this.projectFilePath, err.toString()); + } } } else { this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());