Add file, row and column for ui/builder errors

This commit is contained in:
Panayot Cankov
2015-11-17 18:19:20 +02:00
parent acf8b6e432
commit 8bee3ed2d1
8 changed files with 352 additions and 125 deletions

92
utils/debug.d.ts vendored Normal file
View File

@@ -0,0 +1,92 @@
declare module "utils/debug" {
/**
* A runtime option indicating whether the build has debugging enabled.
*/
export var debug: boolean;
/**
* A class encapsulating information for source code origin.
*/
export class Source {
/**
* Creates a new Source instance by given uri, line and column.
*/
constructor(uri: string, line: number, column: number);
/**
* Gets the URI of the source document;
*/
uri: string;
/**
* Gets the line in the source document.
*/
line: number;
/**
* Gets the position in the source document.
*/
column: number;
/**
* Get the source of an object.
*/
public static get(object: any): Source;
/**
* Set the source of an object.
*/
public static set(object: any, src: Source);
}
/**
* An Error class that provides additional context to an error.
*/
export class ScopeError implements Error {
/**
* Creates a new ScopeError providing addtional context to the child error.
* @param child The child error to extend.
* @param message Additional message to prepend to the child error.
*/
constructor(child: Error, message?: string);
/**
* Gets the child error.
*/
child: Error;
/**
* Gets the error message.
*/
message: string;
/**
* Gets the stack trace.
*/
stack: string;
/**
* Gets the error name.
*/
name: string;
}
/**
* Represents a scope error providing addiot
*/
export class SourceError extends ScopeError {
/**
* Creates a new SourceError by child error, source and optional message.
* @param child The child error to extend.
* @param source The source where the error occured.
* @param message Additonal message to prepend along the source location and the child error's message.
*/
constructor(child: Error, source: Source, message?: string);
/**
* Gets the error source.
*/
source: Source;
}
}

83
utils/debug.ts Normal file
View File

@@ -0,0 +1,83 @@
import { knownFolders } from "file-system"
export var debug = true;
// TODO: Get this from the runtimes...
var applicationRootPath = knownFolders.currentApp().path;
applicationRootPath = applicationRootPath.substr(0, applicationRootPath.length - "app/".length);
export class Source {
private _uri: string;
private _line: number;
private _column: number;
private static _source: symbol = Symbol("source");
private static _appRoot: string;
constructor(uri: string, line: number, column: number) {
if (uri.length > applicationRootPath.length && uri.substr(0, applicationRootPath.length) === applicationRootPath) {
this._uri = "file://" + uri.substr(applicationRootPath.length);
} else {
this._uri = uri;
}
this._line = line;
this._column = column;
}
get uri(): string { return this._uri; }
get line(): number { return this._line; }
get column(): number { return this._column; }
public toString() {
return this._uri + ":" + this._line + ":" + this._column;
}
public static get(object: any): Source {
return object[Source._source];
}
public static set(object: any, src: Source) {
object[Source._source] = src;
}
}
export class ScopeError implements Error {
private _child: Error;
private _message: string;
constructor(child: Error, message?: string) {
if (!child) {
throw new Error("Required child error!");
}
this._child = child;
this._message = message;
}
get child() { return this._child; }
get message() {
if (this._message && this._childMessage) {
// It is a ↳ but the ios fails to show this symbol at the moment.
return this._message + "\n \u21B3" + this._childMessage.replace("\n", "\n ");
}
return this._message || this._childMessage || undefined;
}
get name() { return this.child.name; }
get stack() { return (<any>this.child).stack; }
private get _childMessage(): string {
return this.child.message;
}
public toString() { return "Error: " + this.message; }
}
export class SourceError extends ScopeError {
private _source: Source;
constructor(child: Error, source: Source, message?: string) {
super(child, message ? message + " @" + source + "" : source + "");
this._source = source;
}
get source() { return this._source; }
}