refactor: Accept unknown in errorToConsole to drop as Error casts (#2541)
This commit is contained in:
committed by
dermotduffy
parent
fcef48e75a
commit
95f35bd326
@@ -366,7 +366,7 @@ export class FrigateCamera extends Camera {
|
|||||||
cameraConfig.frigate.camera_name,
|
cameraConfig.frigate.camera_name,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const getGo2RTCStreamMetadata = async (
|
|||||||
timeoutSeconds,
|
timeoutSeconds,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ export class ActionsManager implements ActionsExecutor {
|
|||||||
await actionSet.execute(this._api);
|
await actionSet.execute(this._api);
|
||||||
forwardHaptic('success');
|
forwardHaptic('success');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
forwardHaptic('warning');
|
forwardHaptic('warning');
|
||||||
}
|
}
|
||||||
this._actionsInFlight = this._actionsInFlight.filter((a) => a !== actionSet);
|
this._actionsInFlight = this._actionsInFlight.filter((a) => a !== actionSet);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class IssueStateManager implements IssueReadOnlyState {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Isolate one issue's detection failure so it cannot abort detection
|
// Isolate one issue's detection failure so it cannot abort detection
|
||||||
// for the rest; log so the cause is visible.
|
// for the rest; log so the cause is visible.
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
this._logIfNew(issue);
|
this._logIfNew(issue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export class MediaPlayerManager {
|
|||||||
// Failing to fetch media player information is not considered
|
// Failing to fetch media player information is not considered
|
||||||
// sufficiently serious to block card startup -- it is just logged and we
|
// sufficiently serious to block card startup -- it is just logged and we
|
||||||
// move on.
|
// move on.
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out entities that are marked as hidden (this information is not
|
// Filter out entities that are marked as hidden (this information is not
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export class ViewItemManager {
|
|||||||
try {
|
try {
|
||||||
url = await homeAssistantGetSignedURLIfNecessary(hass, endpoint);
|
url = await homeAssistantGetSignedURLIfNecessary(hass, endpoint);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
url = null;
|
url = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export class GalleryController {
|
|||||||
useCache,
|
useCache,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ export class MediaFilterController {
|
|||||||
try {
|
try {
|
||||||
metadata = await cameraManager.getMediaMetadata();
|
metadata = await cameraManager.getMediaMetadata();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export class SignedURLController implements ReactiveController {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ export class SignedURLController implements ReactiveController {
|
|||||||
PROXY_URL_SIGN_EXPIRY_SECONDS,
|
PROXY_URL_SIGN_EXPIRY_SECONDS,
|
||||||
);
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ export class TimelineDataSource {
|
|||||||
...(this._showRecordings ? [this._refreshRecordings(window)] : []),
|
...(this._showRecordings ? [this._refreshRecordings(window)] : []),
|
||||||
]);
|
]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export class AdvancedCameraCardElementsCore extends LitElement {
|
|||||||
try {
|
try {
|
||||||
element.setConfig(config);
|
element.setConfig(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error, console.error);
|
errorToConsole(e, console.error);
|
||||||
throw new AdvancedCameraCardError(localize('error.invalid_elements_config'));
|
throw new AdvancedCameraCardError(localize('error.invalid_elements_config'));
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
@@ -155,7 +155,7 @@ export class AdvancedCameraCardElementsCore extends LitElement {
|
|||||||
this._renderedElements = elements;
|
this._renderedElements = elements;
|
||||||
this._root = this._createRoot();
|
this._root = this._createRoot();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
fireAdvancedCameraCardEvent<IssueTriggerEventData>(this, 'issue:trigger', {
|
fireAdvancedCameraCardEvent<IssueTriggerEventData>(this, 'issue:trigger', {
|
||||||
key: 'config_error',
|
key: 'config_error',
|
||||||
error: new ElementsCreationError(elements),
|
error: new ElementsCreationError(elements),
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ export class AdvancedCameraCardLiveJSMPEG extends LitElement implements MediaPla
|
|||||||
JSMPEG_URL_SIGN_EXPIRY_SECONDS,
|
JSMPEG_URL_SIGN_EXPIRY_SECONDS,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
const address = response ? convertHTTPAdressToWebsocket(response) : null;
|
const address = response ? convertHTTPAdressToWebsocket(response) : null;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class DeviceRegistryManager {
|
|||||||
type: 'config/device_registry/list',
|
type: 'config/device_registry/list',
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
deviceList.forEach((device) => {
|
deviceList.forEach((device) => {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class EntityRegistryManagerLive implements EntityRegistryManager {
|
|||||||
entity_id: entityID,
|
entity_id: entityID,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this._cache.set(entity.entity_id, entity);
|
this._cache.set(entity.entity_id, entity);
|
||||||
@@ -79,7 +79,7 @@ export class EntityRegistryManagerLive implements EntityRegistryManager {
|
|||||||
type: 'config/entity_registry/list',
|
type: 'config/entity_registry/list',
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
entityList.forEach((entity) => {
|
entityList.forEach((entity) => {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const resolveMedia = async (
|
|||||||
try {
|
try {
|
||||||
resolvedMedia = await homeAssistantWSRequest(hass, resolvedMediaSchema, request);
|
resolvedMedia = await homeAssistantWSRequest(hass, resolvedMediaSchema, request);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
}
|
}
|
||||||
if (cache && resolvedMedia) {
|
if (cache && resolvedMedia) {
|
||||||
cache.set(mediaContentID, resolvedMedia);
|
cache.set(mediaContentID, resolvedMedia);
|
||||||
|
|||||||
+5
-5
@@ -76,13 +76,13 @@ export function contentsChanged(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Log an error as a warning to the console.
|
* Log an error as a warning to the console.
|
||||||
* @param e The Error-like object.
|
* @param e The caught error or error-like value.
|
||||||
* @param func The Console func to call.
|
* @param func The Console func to call.
|
||||||
*/
|
*/
|
||||||
export function errorToConsole(
|
export function errorToConsole(e: unknown, func: CallableFunction = console.warn): void {
|
||||||
e: Error | { message: unknown } | string,
|
if (!e) {
|
||||||
func: CallableFunction = console.warn,
|
return;
|
||||||
): void {
|
}
|
||||||
if (e instanceof AdvancedCameraCardError && e.context) {
|
if (e instanceof AdvancedCameraCardError && e.context) {
|
||||||
func(e, e.context);
|
func(e, e.context);
|
||||||
} else if (typeof e === 'object' && 'message' in e) {
|
} else if (typeof e === 'object' && 'message' in e) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export async function toggleReviewed(
|
|||||||
try {
|
try {
|
||||||
await viewItemManager.reviewMedia(item, newState);
|
await viewItemManager.reviewMedia(item, newState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
item.setReviewed(newState);
|
item.setReviewed(newState);
|
||||||
@@ -55,7 +55,7 @@ export async function toggleFavorite(
|
|||||||
try {
|
try {
|
||||||
await viewItemManager.favorite(item, newState);
|
await viewItemManager.favorite(item, newState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -72,7 +72,7 @@ export async function downloadMedia(
|
|||||||
try {
|
try {
|
||||||
await viewItemManager.download(item);
|
await viewItemManager.download(item);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ export const renderTask = <R>(
|
|||||||
pending: () =>
|
pending: () =>
|
||||||
options?.inProgressFunc?.() ?? renderProgressIndicator(progressConfig),
|
options?.inProgressFunc?.() ?? renderProgressIndicator(progressConfig),
|
||||||
error: (e: unknown) => {
|
error: (e: unknown) => {
|
||||||
errorToConsole(e as Error);
|
errorToConsole(e);
|
||||||
return options?.errorFunc?.(e as Error);
|
return options?.errorFunc?.(e as Error);
|
||||||
},
|
},
|
||||||
complete: completeFunc,
|
complete: completeFunc,
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ describe('errorToConsole', () => {
|
|||||||
errorToConsole('string message');
|
errorToConsole('string message');
|
||||||
expect(spy).toHaveBeenCalledWith('string message');
|
expect(spy).toHaveBeenCalledWith('string message');
|
||||||
});
|
});
|
||||||
|
it('should do nothing given a falsy value', () => {
|
||||||
|
spy.mockClear();
|
||||||
|
errorToConsole(null);
|
||||||
|
expect(spy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// @vitest-environment jsdom
|
// @vitest-environment jsdom
|
||||||
|
|||||||
Reference in New Issue
Block a user