Skip to content

Commit ea76acf

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

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
}

src/lib/icon/icon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class MdIcon extends _MdIconMixinBase implements OnChanges, OnInit, CanCo
128128
case 2:
129129
return <[string, string]>parts;
130130
default:
131-
throw new Error(`Invalid icon name: "${iconName}"`);
131+
throw Error(`Invalid icon name: "${iconName}"`);
132132
}
133133
}
134134

src/lib/input/input-container-errors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88

99
/** @docs-private */
1010
export function getMdInputContainerPlaceholderConflictError(): Error {
11-
return new Error('Placeholder attribute and child element were both specified.');
11+
return Error('Placeholder attribute and child element were both specified.');
1212
}
1313

1414
/** @docs-private */
1515
export function getMdInputContainerUnsupportedTypeError(type: string): Error {
16-
return new Error(`Input type "${type}" isn't supported by md-input-container.`);
16+
return Error(`Input type "${type}" isn't supported by md-input-container.`);
1717
}
1818

1919
/** @docs-private */
2020
export function getMdInputContainerDuplicatedHintError(align: string): Error {
21-
return new Error(`A hint was already declared for 'align="${align}"'.`);
21+
return Error(`A hint was already declared for 'align="${align}"'.`);
2222
}
2323

2424
/** @docs-private */
2525
export function getMdInputContainerMissingMdInputError(): Error {
26-
return new Error('md-input-container must contain an mdInput directive. ' +
26+
return Error('md-input-container must contain an mdInput directive. ' +
2727
'Did you forget to add mdInput to the native input or textarea element?');
2828
}

src/lib/menu/menu-errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @docs-private
1212
*/
1313
export function throwMdMenuMissingError() {
14-
throw new Error(`md-menu-trigger: must pass in an md-menu instance.
14+
throw Error(`md-menu-trigger: must pass in an md-menu instance.
1515
1616
Example:
1717
<md-menu #menu="mdMenu"></md-menu>
@@ -24,7 +24,7 @@ export function throwMdMenuMissingError() {
2424
* @docs-private
2525
*/
2626
export function throwMdMenuInvalidPositionX() {
27-
throw new Error(`x-position value must be either 'before' or after'.
27+
throw Error(`x-position value must be either 'before' or after'.
2828
Example: <md-menu x-position="before" #menu="mdMenu"></md-menu>`);
2929
}
3030

@@ -34,6 +34,6 @@ export function throwMdMenuInvalidPositionX() {
3434
* @docs-private
3535
*/
3636
export function throwMdMenuInvalidPositionY() {
37-
throw new Error(`y-position value must be either 'above' or below'.
37+
throw Error(`y-position value must be either 'above' or below'.
3838
Example: <md-menu y-position="above" #menu="mdMenu"></md-menu>`);
3939
}

src/lib/select/select-errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @docs-private
1313
*/
1414
export function getMdSelectDynamicMultipleError(): Error {
15-
return new Error('Cannot change `multiple` mode of select after initialization.');
15+
return Error('Cannot change `multiple` mode of select after initialization.');
1616
}
1717

1818
/**
@@ -22,5 +22,5 @@ export function getMdSelectDynamicMultipleError(): Error {
2222
* @docs-private
2323
*/
2424
export function getMdSelectNonArrayValueError(): Error {
25-
return new Error('Cannot assign truthy non-array value to select in `multiple` mode.');
25+
return Error('Cannot assign truthy non-array value to select in `multiple` mode.');
2626
}

src/lib/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ class SelectWithErrorSibling {
25562556
})
25572557
export class ThrowsErrorOnInit implements OnInit {
25582558
ngOnInit() {
2559-
throw new Error('Oh no!');
2559+
throw Error('Oh no!');
25602560
}
25612561
}
25622562

src/lib/sidenav/sidenav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {DOCUMENT} from '@angular/platform-browser';
3131

3232
/** Throws an exception when two MdSidenav are matching the same side. */
3333
export function throwMdDuplicatedSidenavError(align: string) {
34-
throw new Error(`A sidenav was already declared for 'align="${align}"'`);
34+
throw Error(`A sidenav was already declared for 'align="${align}"'`);
3535
}
3636

3737

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
9292
/** Attach a component portal as content to this snack bar container. */
9393
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
9494
if (this._portalHost.hasAttached()) {
95-
throw new Error('Attempting to attach snack bar content after content is already attached');
95+
throw Error('Attempting to attach snack bar content after content is already attached');
9696
}
9797

9898
if (this.snackBarConfig.extraClasses) {
@@ -108,7 +108,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
108108

109109
/** Attach a template portal as content to this snack bar container. */
110110
attachTemplatePortal(): Map<string, any> {
111-
throw new Error('Not yet implemented');
111+
throw Error('Not yet implemented');
112112
}
113113

114114
/** Handle end of animations, updating the state of the snackbar. */

src/lib/tooltip/tooltip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const SCROLL_THROTTLE_MS = 20;
5252

5353
/** Throws an error if the user supplied an invalid tooltip position. */
5454
export function throwMdTooltipInvalidPositionError(position: string) {
55-
throw new Error(`Tooltip position "${position}" is invalid.`);
55+
throw Error(`Tooltip position "${position}" is invalid.`);
5656
}
5757

5858
/**

0 commit comments

Comments
 (0)