Skip to content

refactor: shorter error constructors #5135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const MD_AUTOCOMPLETE_VALUE_ACCESSOR: any = {
* Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
*/
export function getMdAutocompleteMissingPanelError(): Error {
return new Error('Attempting to open an undefined instance of `md-autocomplete`. ' +
return Error('Attempting to open an undefined instance of `md-autocomplete`. ' +
'Make sure that the id passed to the `mdAutocomplete` is correct and that ' +
'you\'re attempting to open it after the ngAfterContentInit hook.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/compatibility/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const MATERIAL_COMPATIBILITY_MODE = new InjectionToken<boolean>('md-compa
* @docs-private
*/
export function getMdCompatibilityInvalidPrefixError(prefix: string, nodeName: string) {
return new Error(`The "${prefix}-" prefix cannot be used in ng-material v1 compatibility mode. ` +
return Error(`The "${prefix}-" prefix cannot be used in ng-material v1 compatibility mode. ` +
`It was used on an "${nodeName.toLowerCase()}" element.`);
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/core/portal/portal-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
* @docs-private
*/
export function throwNullPortalError() {
throw new Error('Must provide a portal to attach');
throw Error('Must provide a portal to attach');
}

/**
* Throws an exception when attempting to attach a portal to a host that is already attached.
* @docs-private
*/
export function throwPortalAlreadyAttachedError() {
throw new Error('Host already has a portal attached');
throw Error('Host already has a portal attached');
}

/**
* Throws an exception when attempting to attach a portal to an already-disposed host.
* @docs-private
*/
export function throwPortalHostAlreadyDisposedError() {
throw new Error('This PortalHost has already been disposed');
throw Error('This PortalHost has already been disposed');
}

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

Expand All @@ -44,13 +44,13 @@ export function throwUnknownPortalTypeError() {
* @docs-private
*/
export function throwNullPortalHostError() {
throw new Error('Attempting to attach a portal to a null PortalHost');
throw Error('Attempting to attach a portal to a null PortalHost');
}

/**
* Throws an exception when attempting to detach a portal that is not attached.
* @docs-privatew
*/
export function throwNoPortalAttachedError() {
throw new Error('Attempting to detach a portal that is not attached to a host');
throw Error('Attempting to detach a portal that is not attached to a host');
}
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/** @docs-private */
export function createMissingDateImplError(provider: string) {
return new Error(
return Error(
`MdDatepicker: No provider found for ${provider}. You must import one of the following` +
`modules at your application root: MdNativeDateModule, or provide a custom implementation.`);
}
4 changes: 2 additions & 2 deletions src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class MdDatepicker<D> implements OnDestroy {
*/
_registerInput(input: MdDatepickerInput<D>): void {
if (this._datepickerInput) {
throw new Error('An MdDatepicker can only be associated with a single input.');
throw Error('An MdDatepicker can only be associated with a single input.');
}
this._datepickerInput = input;
this._inputSubscription =
Expand All @@ -211,7 +211,7 @@ export class MdDatepicker<D> implements OnDestroy {
return;
}
if (!this._datepickerInput) {
throw new Error('Attempted to open an MdDatepicker with no associated input.');
throw Error('Attempted to open an MdDatepicker with no associated input.');
}

this.touchUi ? this._openAsDialog() : this._openAsPopup();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {FocusTrapFactory, FocusTrap} from '../core/a11y/focus-trap';
* @docs-private
*/
export function throwMdDialogContentAlreadyAttachedError() {
throw new Error('Attempting to attach dialog content after content is already attached');
throw Error('Attempting to attach dialog content after content is already attached');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/grid-list/grid-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
/** Throw a friendly error if cols property is missing */
private _checkCols() {
if (!this.cols) {
throw new Error(`md-grid-list: must pass in number of columns. ` +
throw Error(`md-grid-list: must pass in number of columns. ` +
`Example: <md-grid-list cols="3">`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/grid-list/tile-coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class TileCoordinator {
/** Finds the next available space large enough to fit the tile. */
private _findMatchingGap(tileCols: number): number {
if (tileCols > this.tracker.length) {
throw new Error(`md-grid-list: tile with colspan ${tileCols} is wider than ` +
throw Error(`md-grid-list: tile with colspan ${tileCols} is wider than ` +
`grid with cols="${this.tracker.length}".`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/grid-list/tile-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class RatioTileStyler extends TileStyler {
let ratioParts = value.split(':');

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

this.rowHeightRatio = parseFloat(ratioParts[0]) / parseFloat(ratioParts[1]);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/icon/icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import 'rxjs/add/observable/throw';
* @docs-private
*/
export function getMdIconNameNotFoundError(iconName: string): Error {
return new Error(`Unable to find icon with the name "${iconName}"`);
return Error(`Unable to find icon with the name "${iconName}"`);
}


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

Expand Down Expand Up @@ -375,7 +375,7 @@ export class MdIconRegistry {
div.innerHTML = str;
const svg = div.querySelector('svg') as SVGElement;
if (!svg) {
throw new Error('<svg> tag not found');
throw Error('<svg> tag not found');
}
return svg;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/icon/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class MdIcon extends _MdIconMixinBase implements OnChanges, OnInit, CanCo
case 2:
return <[string, string]>parts;
default:
throw new Error(`Invalid icon name: "${iconName}"`);
throw Error(`Invalid icon name: "${iconName}"`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/input/input-container-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@

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

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

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

/** @docs-private */
export function getMdInputContainerMissingMdInputError(): Error {
return new Error('md-input-container must contain an mdInput directive. ' +
return Error('md-input-container must contain an mdInput directive. ' +
'Did you forget to add mdInput to the native input or textarea element?');
}
6 changes: 3 additions & 3 deletions src/lib/menu/menu-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @docs-private
*/
export function throwMdMenuMissingError() {
throw new Error(`md-menu-trigger: must pass in an md-menu instance.
throw Error(`md-menu-trigger: must pass in an md-menu instance.

Example:
<md-menu #menu="mdMenu"></md-menu>
Expand All @@ -24,7 +24,7 @@ export function throwMdMenuMissingError() {
* @docs-private
*/
export function throwMdMenuInvalidPositionX() {
throw new Error(`x-position value must be either 'before' or after'.
throw Error(`x-position value must be either 'before' or after'.
Example: <md-menu x-position="before" #menu="mdMenu"></md-menu>`);
}

Expand All @@ -34,6 +34,6 @@ export function throwMdMenuInvalidPositionX() {
* @docs-private
*/
export function throwMdMenuInvalidPositionY() {
throw new Error(`y-position value must be either 'above' or below'.
throw Error(`y-position value must be either 'above' or below'.
Example: <md-menu y-position="above" #menu="mdMenu"></md-menu>`);
}
4 changes: 2 additions & 2 deletions src/lib/select/select-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @docs-private
*/
export function getMdSelectDynamicMultipleError(): Error {
return new Error('Cannot change `multiple` mode of select after initialization.');
return Error('Cannot change `multiple` mode of select after initialization.');
}

/**
Expand All @@ -22,5 +22,5 @@ export function getMdSelectDynamicMultipleError(): Error {
* @docs-private
*/
export function getMdSelectNonArrayValueError(): Error {
return new Error('Cannot assign truthy non-array value to select in `multiple` mode.');
return Error('Cannot assign truthy non-array value to select in `multiple` mode.');
}
2 changes: 1 addition & 1 deletion src/lib/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2556,7 +2556,7 @@ class SelectWithErrorSibling {
})
export class ThrowsErrorOnInit implements OnInit {
ngOnInit() {
throw new Error('Oh no!');
throw Error('Oh no!');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {DOCUMENT} from '@angular/platform-browser';

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


Expand Down
4 changes: 2 additions & 2 deletions src/lib/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MdSnackBarContainer extends BasePortalHost implements OnDestroy {
/** Attach a component portal as content to this snack bar container. */
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
if (this._portalHost.hasAttached()) {
throw new Error('Attempting to attach snack bar content after content is already attached');
throw Error('Attempting to attach snack bar content after content is already attached');
}

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

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

/** Handle end of animations, updating the state of the snackbar. */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const SCROLL_THROTTLE_MS = 20;

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

/**
Expand Down