Skip to content

Commit ea76acf

Browse files
crisbetokara
authored andcommitted
refactor: shorter error constructors (#5135)
1 parent 99fc668 commit ea76acf

File tree

18 files changed

+33
-33
lines changed

18 files changed

+33
-33
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const MD_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
6262
* Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
6363
*/
6464
export function getMdAutocompleteMissingPanelError(): Error {
65-
return new Error('Attempting to open an undefined instance of `md-autocomplete`. ' +
65+
return Error('Attempting to open an undefined instance of `md-autocomplete`. ' +
6666
'Make sure that the id passed to the `mdAutocomplete` is correct and that ' +
6767
'you\'re attempting to open it after the ngAfterContentInit hook.');
6868
}

src/lib/core/compatibility/compatibility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const MATERIAL_COMPATIBILITY_MODE = new InjectionToken<boolean>('md-compa
1616
* @docs-private
1717
*/
1818
export function getMdCompatibilityInvalidPrefixError(prefix: string, nodeName: string) {
19-
return new Error(`The "${prefix}-" prefix cannot be used in ng-material v1 compatibility mode. ` +
19+
return Error(`The "${prefix}-" prefix cannot be used in ng-material v1 compatibility mode. ` +
2020
`It was used on an "${nodeName.toLowerCase()}" element.`);
2121
}
2222

src/lib/core/portal/portal-errors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@
1111
* @docs-private
1212
*/
1313
export function throwNullPortalError() {
14-
throw new Error('Must provide a portal to attach');
14+
throw Error('Must provide a portal to attach');
1515
}
1616

1717
/**
1818
* Throws an exception when attempting to attach a portal to a host that is already attached.
1919
* @docs-private
2020
*/
2121
export function throwPortalAlreadyAttachedError() {
22-
throw new Error('Host already has a portal attached');
22+
throw Error('Host already has a portal attached');
2323
}
2424

2525
/**
2626
* Throws an exception when attempting to attach a portal to an already-disposed host.
2727
* @docs-private
2828
*/
2929
export function throwPortalHostAlreadyDisposedError() {
30-
throw new Error('This PortalHost has already been disposed');
30+
throw Error('This PortalHost has already been disposed');
3131
}
3232

3333
/**
3434
* Throws an exception when attempting to attach an unknown portal type.
3535
* @docs-private
3636
*/
3737
export function throwUnknownPortalTypeError() {
38-
throw new Error('Attempting to attach an unknown Portal type. BasePortalHost accepts either' +
38+
throw Error('Attempting to attach an unknown Portal type. BasePortalHost accepts either' +
3939
'a ComponentPortal or a TemplatePortal.');
4040
}
4141

@@ -44,13 +44,13 @@ export function throwUnknownPortalTypeError() {
4444
* @docs-private
4545
*/
4646
export function throwNullPortalHostError() {
47-
throw new Error('Attempting to attach a portal to a null PortalHost');
47+
throw Error('Attempting to attach a portal to a null PortalHost');
4848
}
4949

5050
/**
5151
* Throws an exception when attempting to detach a portal that is not attached.
5252
* @docs-privatew
5353
*/
5454
export function throwNoPortalAttachedError() {
55-
throw new Error('Attempting to detach a portal that is not attached to a host');
55+
throw Error('Attempting to detach a portal that is not attached to a host');
5656
}

src/lib/datepicker/datepicker-errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** @docs-private */
1010
export function createMissingDateImplError(provider: string) {
11-
return new Error(
11+
return Error(
1212
`MdDatepicker: No provider found for ${provider}. You must import one of the following` +
1313
`modules at your application root: MdNativeDateModule, or provide a custom implementation.`);
1414
}

src/lib/datepicker/datepicker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class MdDatepicker<D> implements OnDestroy {
198198
*/
199199
_registerInput(input: MdDatepickerInput<D>): void {
200200
if (this._datepickerInput) {
201-
throw new Error('An MdDatepicker can only be associated with a single input.');
201+
throw Error('An MdDatepicker can only be associated with a single input.');
202202
}
203203
this._datepickerInput = input;
204204
this._inputSubscription =
@@ -211,7 +211,7 @@ export class MdDatepicker<D> implements OnDestroy {
211211
return;
212212
}
213213
if (!this._datepickerInput) {
214-
throw new Error('Attempted to open an MdDatepicker with no associated input.');
214+
throw Error('Attempted to open an MdDatepicker with no associated input.');
215215
}
216216

217217
this.touchUi ? this._openAsDialog() : this._openAsPopup();

src/lib/dialog/dialog-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {FocusTrapFactory, FocusTrap} from '../core/a11y/focus-trap';
3737
* @docs-private
3838
*/
3939
export function throwMdDialogContentAlreadyAttachedError() {
40-
throw new Error('Attempting to attach dialog content after content is already attached');
40+
throw Error('Attempting to attach dialog content after content is already attached');
4141
}
4242

4343
/**

src/lib/grid-list/grid-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
104104
/** Throw a friendly error if cols property is missing */
105105
private _checkCols() {
106106
if (!this.cols) {
107-
throw new Error(`md-grid-list: must pass in number of columns. ` +
107+
throw Error(`md-grid-list: must pass in number of columns. ` +
108108
`Example: <md-grid-list cols="3">`);
109109
}
110110
}

src/lib/grid-list/tile-coordinator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class TileCoordinator {
7676
/** Finds the next available space large enough to fit the tile. */
7777
private _findMatchingGap(tileCols: number): number {
7878
if (tileCols > this.tracker.length) {
79-
throw new Error(`md-grid-list: tile with colspan ${tileCols} is wider than ` +
79+
throw Error(`md-grid-list: tile with colspan ${tileCols} is wider than ` +
8080
`grid with cols="${this.tracker.length}".`);
8181
}
8282

src/lib/grid-list/tile-styler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class RatioTileStyler extends TileStyler {
207207
let ratioParts = value.split(':');
208208

209209
if (ratioParts.length !== 2) {
210-
throw new Error(`md-grid-list: invalid ratio given for row-height: "${value}"`);
210+
throw Error(`md-grid-list: invalid ratio given for row-height: "${value}"`);
211211
}
212212

213213
this.rowHeightRatio = parseFloat(ratioParts[0]) / parseFloat(ratioParts[1]);

src/lib/icon/icon-registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import 'rxjs/add/observable/throw';
2727
* @docs-private
2828
*/
2929
export function getMdIconNameNotFoundError(iconName: string): Error {
30-
return new Error(`Unable to find icon with the name "${iconName}"`);
30+
return Error(`Unable to find icon with the name "${iconName}"`);
3131
}
3232

3333

@@ -37,7 +37,7 @@ export function getMdIconNameNotFoundError(iconName: string): Error {
3737
* @docs-private
3838
*/
3939
export function getMdIconNoHttpProviderError(): Error {
40-
return new Error('Could not find Http provider for use with Angular Material icons. ' +
40+
return Error('Could not find Http provider for use with Angular Material icons. ' +
4141
'Please include the HttpModule from @angular/http in your app imports.');
4242
}
4343

@@ -375,7 +375,7 @@ export class MdIconRegistry {
375375
div.innerHTML = str;
376376
const svg = div.querySelector('svg') as SVGElement;
377377
if (!svg) {
378-
throw new Error('<svg> tag not found');
378+
throw Error('<svg> tag not found');
379379
}
380380
return svg;
381381
}

0 commit comments

Comments
 (0)