diff --git a/src/components/grid-list/grid-list-errors.ts b/src/components/grid-list/grid-list-errors.ts index 65dc797b0283..cc38681a16ce 100644 --- a/src/components/grid-list/grid-list-errors.ts +++ b/src/components/grid-list/grid-list-errors.ts @@ -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: `); } @@ -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}".`); } @@ -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}"`); } diff --git a/src/components/icon/icon-registry.ts b/src/components/icon/icon-registry.ts index 9fd8be75ae7f..462aae1f6737 100644 --- a/src/components/icon/icon-registry.ts +++ b/src/components/icon/icon-registry.ts @@ -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}"`); } @@ -14,7 +15,7 @@ export class MdIconNameNotFoundError extends Error { * Exception thrown when attempting to load SVG content that does not contain the expected * tag. */ -export class MdIconSvgTagNotFoundError extends Error { +export class MdIconSvgTagNotFoundError extends MdError { constructor() { super(' tag not found'); } diff --git a/src/components/icon/icon.ts b/src/components/icon/icon.ts index 87c2a7171ab1..982b9db75778 100644 --- a/src/components/icon/icon.ts +++ b/src/components/icon/icon.ts @@ -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}"`); } diff --git a/src/components/input/input.ts b/src/components/input/input.ts index c90d27ae0a4c..363e07898d5f 100644 --- a/src/components/input/input.ts +++ b/src/components/input/input.ts @@ -17,6 +17,7 @@ import { ControlValueAccessor } from '@angular/common'; import {BooleanFieldValue} from '../../core/annotations/field-value'; +import {MdError} from '../../core/errors/error'; const noop = () => {}; @@ -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}"'.`); } diff --git a/src/components/sidenav/sidenav.ts b/src/components/sidenav/sidenav.ts index 8482baff6de6..9007cd2b5c71 100644 --- a/src/components/sidenav/sidenav.ts +++ b/src/components/sidenav/sidenav.ts @@ -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}"'`); } diff --git a/src/core/errors/error.ts b/src/core/errors/error.ts new file mode 100644 index 000000000000..d24aa3047830 --- /dev/null +++ b/src/core/errors/error.ts @@ -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; + } +} diff --git a/src/core/portal/portal-errors.ts b/src/core/portal/portal-errors.ts index bef0ef3d7986..b83a1790d9aa 100644 --- a/src/core/portal/portal-errors.ts +++ b/src/core/portal/portal-errors.ts @@ -1,5 +1,7 @@ +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 ' + @@ -7,29 +9,29 @@ export class MdComponentPortalAttachedToDomWithoutOriginError extends Error { } } -/** 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. ' + @@ -37,15 +39,15 @@ export class MdUnknownPortalTypeErron extends Error { } } -/** 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'); } diff --git a/src/core/portal/portal.ts b/src/core/portal/portal.ts index b34c1f82530a..1676cc9a4d29 100644 --- a/src/core/portal/portal.ts +++ b/src/core/portal/portal.ts @@ -2,10 +2,10 @@ import {TemplateRef, Type, ViewContainerRef, ElementRef, ComponentRef} from '@an import { MdNullPortalHostError, MdPortalAlreadyAttachedError, - MdNoPortalAttachedErron, + MdNoPortalAttachedError, MdNullPortalError, MdPortalHostAlreadyDisposedError, - MdUnknownPortalTypeErron + MdUnknownPortalTypeError } from './portal-errors'; @@ -34,7 +34,7 @@ export abstract class Portal { detach(): Promise { let host = this._attachedHost; if (host == null) { - throw new MdNoPortalAttachedErron(); + throw new MdNoPortalAttachedError(); } this._attachedHost = null; @@ -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>;