Skip to content

Commit 4a25b7f

Browse files
committed
fix(errors): ensure error message is set
1 parent 0f89b8d commit 4a25b7f

File tree

8 files changed

+46
-27
lines changed

8 files changed

+46
-27
lines changed

src/components/grid-list/grid-list-errors.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import {MdError} from '../../core/errors/error';
2+
13
/**
24
* Exception thrown when cols property is missing from grid-list
35
*/
4-
export class MdGridListColsError extends Error {
6+
export class MdGridListColsError extends MdError {
57
constructor() {
68
super(`md-grid-list: must pass in number of columns. Example: <md-grid-list cols="3">`);
79
}
@@ -10,7 +12,7 @@ export class MdGridListColsError extends Error {
1012
/**
1113
* Exception thrown when a tile's colspan is longer than the number of cols in list
1214
*/
13-
export class MdGridTileTooWideError extends Error {
15+
export class MdGridTileTooWideError extends MdError {
1416
constructor(cols: number, listLength: number) {
1517
super(`Tile with colspan ${cols} is wider than grid with cols="${listLength}".`);
1618
}
@@ -19,7 +21,7 @@ export class MdGridTileTooWideError extends Error {
1921
/**
2022
* Exception thrown when an invalid ratio is passed in as a rowHeight
2123
*/
22-
export class MdGridListBadRatioError extends Error {
24+
export class MdGridListBadRatioError extends MdError {
2325
constructor(value: string) {
2426
super(`md-grid-list: invalid ratio given for row-height: "${value}"`);
2527
}

src/components/icon/icon-registry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {Injectable} from '@angular/core';
22
import {Http} from '@angular/http';
33
import {Observable} from 'rxjs/Rx';
4+
import {MdError} from '../../core/errors/error';
45

56

67
/** Exception thrown when attempting to load an icon with a name that cannot be found. */
7-
export class MdIconNameNotFoundError extends Error {
8+
export class MdIconNameNotFoundError extends MdError {
89
constructor(iconName: string) {
910
super(`Unable to find icon with the name "${iconName}"`);
1011
}
@@ -14,7 +15,7 @@ export class MdIconNameNotFoundError extends Error {
1415
* Exception thrown when attempting to load SVG content that does not contain the expected
1516
* <svg> tag.
1617
*/
17-
export class MdIconSvgTagNotFoundError extends Error {
18+
export class MdIconSvgTagNotFoundError extends MdError {
1819
constructor() {
1920
super('<svg> tag not found');
2021
}

src/components/icon/icon.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
AfterViewChecked
1212
} from '@angular/core';
1313
import {MdIconRegistry} from './icon-registry';
14+
import {MdError} from '../../core/errors/error';
1415
export {MdIconRegistry} from './icon-registry';
1516

1617

1718
/** Exception thrown when an invalid icon name is passed to an md-icon component. */
18-
export class MdIconInvalidNameError extends Error {
19+
export class MdIconInvalidNameError extends MdError {
1920
constructor(iconName: string) {
2021
super(`Invalid icon name: "${name}"`);
2122
}

src/components/input/input.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ControlValueAccessor
1818
} from '@angular/common';
1919
import {BooleanFieldValue} from '../../core/annotations/field-value';
20+
import {MdError} from '../../core/errors/error';
2021

2122

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

4041

41-
export class MdInputPlaceholderConflictError extends Error {
42+
export class MdInputPlaceholderConflictError extends MdError {
4243
constructor() {
4344
super('Placeholder attribute and child element were both specified.');
4445
}
4546
}
4647

47-
export class MdInputUnsupportedTypeError extends Error {
48+
export class MdInputUnsupportedTypeError extends MdError {
4849
constructor(type: string) {
4950
super(`Input type "${type}" isn't supported by md-input.`);
5051
}
5152
}
5253

53-
export class MdInputDuplicatedHintError extends Error {
54+
export class MdInputDuplicatedHintError extends MdError {
5455
constructor(align: string) {
5556
super(`A hint was already declared for 'align="${align}"'.`);
5657
}

src/components/sidenav/sidenav.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import {
1717
} from '@angular/core';
1818
import {Dir} from '../../core/rtl/dir';
1919
import {PromiseCompleter} from '../../core/async/promise-completer';
20+
import {MdError} from '../../core/errors/error';
2021

2122

2223
/**
2324
* Exception thrown when two MdSidenav are matching the same side.
2425
*/
25-
export class MdDuplicatedSidenavError extends Error {
26+
export class MdDuplicatedSidenavError extends MdError {
2627
constructor(align: string) {
2728
super(`A sidenav was already declared for 'align="${align}"'`);
2829
}

src/core/errors/error.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// TODO(kara): Revisit why error messages are not being properly set.
2+
3+
/**
4+
* Wrapper around Error that sets the error message.
5+
*/
6+
export class MdError extends Error {
7+
constructor(value: string) {
8+
super();
9+
super.message = value;
10+
}
11+
}

src/core/portal/portal-errors.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
1+
import {MdError} from '../errors/error';
2+
13
/** Exception thrown when a ComponentPortal is attached to a DomPortalHost without an origin. */
2-
export class MdComponentPortalAttachedToDomWithoutOriginError extends Error {
4+
export class MdComponentPortalAttachedToDomWithoutOriginError extends MdError {
35
constructor() {
46
super(
57
'A ComponentPortal must have an origin set when attached to a DomPortalHost ' +
68
'because the DOM element is not part of the Angular application context.');
79
}
810
}
911

10-
/** Exception thrown when attmepting to attach a null portal to a host. */
11-
export class MdNullPortalError extends Error {
12+
/** Exception thrown when attempting to attach a null portal to a host. */
13+
export class MdNullPortalError extends MdError {
1214
constructor() {
1315
super('Must provide a portal to attach');
1416
}
1517
}
1618

17-
/** Exception thrown when attmepting to attach a portal to a host that is already attached. */
18-
export class MdPortalAlreadyAttachedError extends Error {
19+
/** Exception thrown when attempting to attach a portal to a host that is already attached. */
20+
export class MdPortalAlreadyAttachedError extends MdError {
1921
constructor() {
2022
super('Host already has a portal attached');
2123
}
2224
}
2325

24-
/** Exception thrown when attmepting to attach a portal to an already-disposed host. */
25-
export class MdPortalHostAlreadyDisposedError extends Error {
26+
/** Exception thrown when attempting to attach a portal to an already-disposed host. */
27+
export class MdPortalHostAlreadyDisposedError extends MdError {
2628
constructor() {
2729
super('This PortalHost has already been disposed');
2830
}
2931
}
3032

31-
/** Exception thrown when attmepting to attach an unknown portal type. */
32-
export class MdUnknownPortalTypeErron extends Error {
33+
/** Exception thrown when attempting to attach an unknown portal type. */
34+
export class MdUnknownPortalTypeError extends MdError {
3335
constructor() {
3436
super(
3537
'Attempting to attach an unknown Portal type. ' +
3638
'BasePortalHost accepts either a ComponentPortal or a TemplatePortal.');
3739
}
3840
}
3941

40-
/** Exception thrown when attmepting to attach a portal to a null host. */
41-
export class MdNullPortalHostError extends Error {
42+
/** Exception thrown when attempting to attach a portal to a null host. */
43+
export class MdNullPortalHostError extends MdError {
4244
constructor() {
4345
super('Attmepting to attach a portal to a null PortalHost');
4446
}
4547
}
4648

47-
/** Exception thrown when attmepting to detach a portal that is not attached. */
48-
export class MdNoPortalAttachedErron extends Error {
49+
/** Exception thrown when attempting to detach a portal that is not attached. */
50+
export class MdNoPortalAttachedError extends MdError {
4951
constructor() {
5052
super('Attmepting to detach a portal that is not attached to a host');
5153
}

src/core/portal/portal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {TemplateRef, Type, ViewContainerRef, ElementRef, ComponentRef} from '@an
22
import {
33
MdNullPortalHostError,
44
MdPortalAlreadyAttachedError,
5-
MdNoPortalAttachedErron,
5+
MdNoPortalAttachedError,
66
MdNullPortalError,
77
MdPortalHostAlreadyDisposedError,
8-
MdUnknownPortalTypeErron
8+
MdUnknownPortalTypeError
99
} from './portal-errors';
1010

1111

@@ -34,7 +34,7 @@ export abstract class Portal<T> {
3434
detach(): Promise<void> {
3535
let host = this._attachedHost;
3636
if (host == null) {
37-
throw new MdNoPortalAttachedErron();
37+
throw new MdNoPortalAttachedError();
3838
}
3939

4040
this._attachedHost = null;
@@ -172,7 +172,7 @@ export abstract class BasePortalHost implements PortalHost {
172172
return this.attachTemplatePortal(portal);
173173
}
174174

175-
throw new MdUnknownPortalTypeErron();
175+
throw new MdUnknownPortalTypeError();
176176
}
177177

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

0 commit comments

Comments
 (0)