mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(errors): ensure error message is set
This commit is contained in:
@@ -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">`);
|
||||
}
|
||||
@@ -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}"`);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* <svg> tag.
|
||||
*/
|
||||
export class MdIconSvgTagNotFoundError extends Error {
|
||||
export class MdIconSvgTagNotFoundError extends MdError {
|
||||
constructor() {
|
||||
super('<svg> tag not found');
|
||||
}
|
||||
|
||||
@@ -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}"`);
|
||||
}
|
||||
|
||||
@@ -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}"'.`);
|
||||
}
|
||||
|
||||
@@ -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}"'`);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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<T> {
|
||||
detach(): Promise<void> {
|
||||
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<ComponentRef<any>>;
|
||||
|
||||
Reference in New Issue
Block a user