Skip to content

Restructure error messaging #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ module.exports = function(grunt) {
},

devlib: {
src: ["lib/**/*.ts", "!lib/common/node_modules/**/*.ts"],
src: ["lib/**/*.ts", "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts"],
reference: "lib/.d.ts"
},

devall: {
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!lib/common/test/.d.ts"],
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!lib/common/test/.d.ts"],
reference: "lib/.d.ts"
},

release_build: {
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts"],
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts"],
reference: "lib/.d.ts",
options: {
sourceMap: false,
Expand All @@ -61,7 +61,7 @@ module.exports = function(grunt) {
tslint: {
build: {
files: {
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!**/*.d.ts"]
src: ["lib/**/*.ts", "test/**/*.ts", "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts", "lib/common/test/unit-tests/**/*.ts", "definitions/**/*.ts", "!**/*.d.ts"]
},
options: {
configuration: grunt.file.readJSON("./tslint.json")
Expand All @@ -71,7 +71,7 @@ module.exports = function(grunt) {

watch: {
devall: {
files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts"],
files: ["lib/**/*.ts", 'test/**/*.ts', "!lib/common/node_modules/**/*.ts", "!lib/common/messages/**/*.ts"],
tasks: [
'ts:devall',
'shell:npm_test'
Expand Down
13 changes: 13 additions & 0 deletions lib/messages.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///<reference path=".d.ts"/>
//
// automatically generated code; do not edit manually!
//
interface IMessages{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've generated the same exact interface in common-lib - https://github.com/telerik/mobile-cli-lib/pull/484/files#diff-2f056d897a840743988e1666c5f9b1baR5. Can we reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I was not able to reuse any parts of the interface due to the following scenario:
These interfaces are generated based upon json files - one default one in the common lib and client-specific ones inside each client respectively. This means that a following case is possible:
Common json file:

{ 
    MessagesObject: {
        Message1: "Some message",
        Message2: "Some other message"
    }
}

Client json file:

{ 
    MessagesObject: {
        Message1: "Some overriden message"
    }
}

This would mean that the interface, generated from the client json file won't be able to extend the interface, generated from the common json because it wouldn't compile.

Personally I don't feel like this is a major issue, because all of this code is generated anyways.

Devices : {
NotFoundDeviceByIdentifierErrorMessage: string;
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: string;
NotFoundDeviceByIndexErrorMessage: string;
};

}

16 changes: 16 additions & 0 deletions lib/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
///<reference path=".d.ts"/>
"use strict";
//
// automatically generated code; do not edit manually!
//

export class Messages implements IMessages{
Devices = {
NotFoundDeviceByIdentifierErrorMessage: "Devices.NotFoundDeviceByIdentifierErrorMessage",
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: "Devices.NotFoundDeviceByIdentifierErrorMessageWithIdentifier",
NotFoundDeviceByIndexErrorMessage: "Devices.NotFoundDeviceByIndexErrorMessage",
};

}
$injector.register('messages', Messages);

3 changes: 3 additions & 0 deletions lib/nativescript-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fiber(() => {

let commandDispatcher: ICommandDispatcher = $injector.resolve("commandDispatcher");

let messages: IMessagesService = $injector.resolve("$messagesService");
messages.pathsToMessageJsonFiles = [/* Place client-specific json message file paths here */];

if (process.argv[2] === "completion") {
commandDispatcher.completeCommand().wait();
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/plugin-variables-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ProjectData} from "../lib/project-data";
import {ProjectDataService} from "../lib/services/project-data-service";
import {ProjectHelper} from "../lib/common/project-helper";
import {StaticConfig} from "../lib/config";
import {MessagesService} from "../lib/common/services/messages-service";
import {Yok} from '../lib/common/yok';
import * as stubs from './stubs';
import * as path from "path";
Expand All @@ -22,6 +23,7 @@ temp.track();
function createTestInjector(): IInjector {
let testInjector = new Yok();

testInjector.register("messagesService", MessagesService);
testInjector.register("errors", Errors);
testInjector.register("fs", FileSystem);
testInjector.register("hostInfo", HostInfo);
Expand Down
3 changes: 2 additions & 1 deletion test/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {ResourceLoader} from "../lib/common/resource-loader";
import {EOL} from "os";
import {PluginsService} from "../lib/services/plugins-service";
import {AddPluginCommand} from "../lib/commands/plugin/add-plugin";
import {MessagesService} from "../lib/common/services/messages-service";
import {Builder} from "../lib/tools/broccoli/builder";
import {AndroidProjectService} from "../lib/services/android-project-service";
import {AndroidToolsInfo} from "../lib/android-tools-info";
Expand All @@ -37,7 +38,7 @@ let isErrorThrown = false;

function createTestInjector() {
let testInjector = new Yok();

testInjector.register("messagesService", MessagesService);
testInjector.register("npm", NodePackageManager);
testInjector.register("fs", FileSystem);
testInjector.register("projectData", ProjectData);
Expand Down