Skip to content

Commit

Permalink
fix(errors): ensure error message is set
Browse files Browse the repository at this point in the history
  • Loading branch information
kara committed May 10, 2016
1 parent 0f89b8d commit 4a25b7f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/components/grid-list/grid-list-errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {MdError} from '../../core/errors/error';

/**
* Exception thrown when cols property is missing from grid-list
*/
export class MdGridListColsError extends Error {
export class MdGridListColsError extends MdError {
constructor() {
super(`md-grid-list: must pass in number of columns. Example: <md-grid-list cols="3">`);
}
Expand All @@ -10,7 +12,7 @@ export class MdGridListColsError extends Error {
/**
* Exception thrown when a tile's colspan is longer than the number of cols in list
*/
export class MdGridTileTooWideError extends Error {
export class MdGridTileTooWideError extends MdError {
constructor(cols: number, listLength: number) {
super(`Tile with colspan ${cols} is wider than grid with cols="${listLength}".`);
}
Expand All @@ -19,7 +21,7 @@ export class MdGridTileTooWideError extends Error {
/**
* Exception thrown when an invalid ratio is passed in as a rowHeight
*/
export class MdGridListBadRatioError extends Error {
export class MdGridListBadRatioError extends MdError {
constructor(value: string) {
super(`md-grid-list: invalid ratio given for row-height: "${value}"`);
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/icon/icon-registry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {Observable} from 'rxjs/Rx';
import {MdError} from '../../core/errors/error';


/** Exception thrown when attempting to load an icon with a name that cannot be found. */
export class MdIconNameNotFoundError extends Error {
export class MdIconNameNotFoundError extends MdError {
constructor(iconName: string) {
super(`Unable to find icon with the name "${iconName}"`);
}
Expand All @@ -14,7 +15,7 @@ export class MdIconNameNotFoundError extends Error {
* Exception thrown when attempting to load SVG content that does not contain the expected
* <svg> tag.
*/
export class MdIconSvgTagNotFoundError extends Error {
export class MdIconSvgTagNotFoundError extends MdError {
constructor() {
super('<svg> tag not found');
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
AfterViewChecked
} from '@angular/core';
import {MdIconRegistry} from './icon-registry';
import {MdError} from '../../core/errors/error';
export {MdIconRegistry} from './icon-registry';


/** Exception thrown when an invalid icon name is passed to an md-icon component. */
export class MdIconInvalidNameError extends Error {
export class MdIconInvalidNameError extends MdError {
constructor(iconName: string) {
super(`Invalid icon name: "${name}"`);
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ControlValueAccessor
} from '@angular/common';
import {BooleanFieldValue} from '../../core/annotations/field-value';
import {MdError} from '../../core/errors/error';


const noop = () => {};
Expand All @@ -38,19 +39,19 @@ const MD_INPUT_INVALID_INPUT_TYPE = [
let nextUniqueId = 0;


export class MdInputPlaceholderConflictError extends Error {
export class MdInputPlaceholderConflictError extends MdError {
constructor() {
super('Placeholder attribute and child element were both specified.');
}
}

export class MdInputUnsupportedTypeError extends Error {
export class MdInputUnsupportedTypeError extends MdError {
constructor(type: string) {
super(`Input type "${type}" isn't supported by md-input.`);
}
}

export class MdInputDuplicatedHintError extends Error {
export class MdInputDuplicatedHintError extends MdError {
constructor(align: string) {
super(`A hint was already declared for 'align="${align}"'.`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import {
} from '@angular/core';
import {Dir} from '../../core/rtl/dir';
import {PromiseCompleter} from '../../core/async/promise-completer';
import {MdError} from '../../core/errors/error';


/**
* Exception thrown when two MdSidenav are matching the same side.
*/
export class MdDuplicatedSidenavError extends Error {
export class MdDuplicatedSidenavError extends MdError {
constructor(align: string) {
super(`A sidenav was already declared for 'align="${align}"'`);
}
Expand Down
11 changes: 11 additions & 0 deletions src/core/errors/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// TODO(kara): Revisit why error messages are not being properly set.

/**
* Wrapper around Error that sets the error message.
*/
export class MdError extends Error {
constructor(value: string) {
super();
super.message = value;
}
}
28 changes: 15 additions & 13 deletions src/core/portal/portal-errors.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
import {MdError} from '../errors/error';

/** Exception thrown when a ComponentPortal is attached to a DomPortalHost without an origin. */
export class MdComponentPortalAttachedToDomWithoutOriginError extends Error {
export class MdComponentPortalAttachedToDomWithoutOriginError extends MdError {
constructor() {
super(
'A ComponentPortal must have an origin set when attached to a DomPortalHost ' +
'because the DOM element is not part of the Angular application context.');
}
}

/** Exception thrown when attmepting to attach a null portal to a host. */
export class MdNullPortalError extends Error {
/** Exception thrown when attempting to attach a null portal to a host. */
export class MdNullPortalError extends MdError {
constructor() {
super('Must provide a portal to attach');
}
}

/** Exception thrown when attmepting to attach a portal to a host that is already attached. */
export class MdPortalAlreadyAttachedError extends Error {
/** Exception thrown when attempting to attach a portal to a host that is already attached. */
export class MdPortalAlreadyAttachedError extends MdError {
constructor() {
super('Host already has a portal attached');
}
}

/** Exception thrown when attmepting to attach a portal to an already-disposed host. */
export class MdPortalHostAlreadyDisposedError extends Error {
/** Exception thrown when attempting to attach a portal to an already-disposed host. */
export class MdPortalHostAlreadyDisposedError extends MdError {
constructor() {
super('This PortalHost has already been disposed');
}
}

/** Exception thrown when attmepting to attach an unknown portal type. */
export class MdUnknownPortalTypeErron extends Error {
/** Exception thrown when attempting to attach an unknown portal type. */
export class MdUnknownPortalTypeError extends MdError {
constructor() {
super(
'Attempting to attach an unknown Portal type. ' +
'BasePortalHost accepts either a ComponentPortal or a TemplatePortal.');
}
}

/** Exception thrown when attmepting to attach a portal to a null host. */
export class MdNullPortalHostError extends Error {
/** Exception thrown when attempting to attach a portal to a null host. */
export class MdNullPortalHostError extends MdError {
constructor() {
super('Attmepting to attach a portal to a null PortalHost');
}
}

/** Exception thrown when attmepting to detach a portal that is not attached. */
export class MdNoPortalAttachedErron extends Error {
/** Exception thrown when attempting to detach a portal that is not attached. */
export class MdNoPortalAttachedError extends MdError {
constructor() {
super('Attmepting to detach a portal that is not attached to a host');
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/portal/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {TemplateRef, Type, ViewContainerRef, ElementRef, ComponentRef} from '@an
import {
MdNullPortalHostError,
MdPortalAlreadyAttachedError,
MdNoPortalAttachedErron,
MdNoPortalAttachedError,
MdNullPortalError,
MdPortalHostAlreadyDisposedError,
MdUnknownPortalTypeErron
MdUnknownPortalTypeError
} from './portal-errors';


Expand Down Expand Up @@ -34,7 +34,7 @@ export abstract class Portal<T> {
detach(): Promise<void> {
let host = this._attachedHost;
if (host == null) {
throw new MdNoPortalAttachedErron();
throw new MdNoPortalAttachedError();
}

this._attachedHost = null;
Expand Down Expand Up @@ -172,7 +172,7 @@ export abstract class BasePortalHost implements PortalHost {
return this.attachTemplatePortal(portal);
}

throw new MdUnknownPortalTypeErron();
throw new MdUnknownPortalTypeError();
}

abstract attachComponentPortal(portal: ComponentPortal): Promise<ComponentRef<any>>;
Expand Down

0 comments on commit 4a25b7f

Please sign in to comment.