diff --git a/packages/frontend/src/components/MkUrlPreview.vue b/packages/frontend/src/components/MkUrlPreview.vue index cc2229a819..1a194ae9db 100644 --- a/packages/frontend/src/components/MkUrlPreview.vue +++ b/packages/frontend/src/components/MkUrlPreview.vue @@ -85,7 +85,6 @@ import { deviceKind } from '@/scripts/device-kind'; import MkButton from '@/components/MkButton.vue'; import { versatileLang } from '@/scripts/intl-const'; import { defaultStore } from '@/store'; -import { ErrorHandling } from '@/error'; type SummalyResult = Awaited>; @@ -125,7 +124,7 @@ let tweetHeight = $ref(150); let unknownUrl = $ref(false); const requestUrl = new URL(props.url); -if (!['http:', 'https:'].includes(requestUrl.protocol)) throw ErrorHandling('invalid url'); +if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url'); if (requestUrl.hostname === 'twitter.com' || requestUrl.hostname === 'mobile.twitter.com') { const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/); diff --git a/packages/frontend/src/components/MkYouTubePlayer.vue b/packages/frontend/src/components/MkYouTubePlayer.vue index 64e715ea20..9b9c3d5ec4 100644 --- a/packages/frontend/src/components/MkYouTubePlayer.vue +++ b/packages/frontend/src/components/MkYouTubePlayer.vue @@ -27,14 +27,13 @@ SPDX-License-Identifier: AGPL-3.0-only import MkWindow from '@/components/MkWindow.vue'; import { versatileLang } from '@/scripts/intl-const'; import { defaultStore } from '@/store'; -import { ErrorHandling } from '@/error'; const props = defineProps<{ url: string; }>(); const requestUrl = new URL(props.url); -if (!['http:', 'https:'].includes(requestUrl.protocol)) throw ErrorHandling('invalid url'); +if (!['http:', 'https:'].includes(requestUrl.protocol)) throw new Error('invalid url'); let fetching = $ref(true); let title = $ref(null); diff --git a/packages/frontend/src/components/global/MkUrl.vue b/packages/frontend/src/components/global/MkUrl.vue index 0f76e436e0..6bcfe3e1a5 100644 --- a/packages/frontend/src/components/global/MkUrl.vue +++ b/packages/frontend/src/components/global/MkUrl.vue @@ -30,7 +30,6 @@ import { url as local } from '@/config'; import * as os from '@/os'; import { useTooltip } from '@/scripts/use-tooltip'; import { safeURIDecode } from '@/scripts/safe-uri-decode'; -import { ErrorHandling } from '@/error'; const props = defineProps<{ url: string; @@ -39,7 +38,7 @@ const props = defineProps<{ const self = props.url.startsWith(local); const url = new URL(props.url); -if (!['http:', 'https:'].includes(url.protocol)) throw ErrorHandling('invalid url'); +if (!['http:', 'https:'].includes(url.protocol)) throw new Error('invalid url'); const el = ref(); useTooltip(el, (showing) => { diff --git a/packages/frontend/src/error.ts b/packages/frontend/src/error.ts deleted file mode 100644 index 865d276496..0000000000 --- a/packages/frontend/src/error.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function ErrorHandling(message: string): Error { - const error = new Error(message); - if (process.env.NODE_ENV === 'production') { - error.stack = undefined; - } - return error; -} diff --git a/packages/frontend/src/pages/auth.vue b/packages/frontend/src/pages/auth.vue index 82a6eefe02..2cc396fc24 100644 --- a/packages/frontend/src/pages/auth.vue +++ b/packages/frontend/src/pages/auth.vue @@ -50,7 +50,6 @@ import * as os from '@/os'; import { $i, login } from '@/account'; import { definePageMetadata } from '@/scripts/page-metadata'; import { i18n } from '@/i18n'; -import { ErrorHandling } from '@/error'; const props = defineProps<{ token: string; @@ -63,7 +62,7 @@ function accepted() { state = 'accepted'; if (session && session.app.callbackUrl) { const url = new URL(session.app.callbackUrl); - if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw ErrorHandling('invalid url'); + if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url'); location.href = `${session.app.callbackUrl}?token=${session.token}`; } } diff --git a/packages/frontend/src/pages/follow.vue b/packages/frontend/src/pages/follow.vue index 76c2157f91..de3b4a57ac 100644 --- a/packages/frontend/src/pages/follow.vue +++ b/packages/frontend/src/pages/follow.vue @@ -14,7 +14,6 @@ import * as Acct from 'misskey-js/built/acct'; import * as os from '@/os'; import { mainRouter } from '@/router'; import { i18n } from '@/i18n'; -import { ErrorHandling } from '@/error'; async function follow(user): Promise { const { canceled } = await os.confirm({ @@ -34,7 +33,7 @@ async function follow(user): Promise { const acct = new URL(location.href).searchParams.get('acct'); if (acct == null) { - throw ErrorHandling('acct required'); + throw new Error('acct required'); } let promise; diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index c68c21fa81..24355c0556 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -136,7 +136,6 @@ import MkUserCardMini from '@/components/MkUserCardMini.vue'; import MkPagination from '@/components/MkPagination.vue'; import { getProxiedImageUrlNullable } from '@/scripts/media-proxy'; import { dateString } from '@/filters/date'; -import { ErrorHandling } from '@/error'; const props = defineProps<{ host: string; @@ -174,8 +173,8 @@ async function fetch(): Promise { } async function toggleBlock(): Promise { - if (!meta) throw ErrorHandling('No meta?'); - if (!instance) throw ErrorHandling('No instance?'); + if (!meta) throw new Error('No meta?'); + if (!instance) throw new Error('No instance?'); const { host } = instance; await os.api('admin/update-meta', { blockedHosts: isBlocked ? meta.blockedHosts.concat([host]) : meta.blockedHosts.filter(x => x !== host), @@ -183,7 +182,7 @@ async function toggleBlock(): Promise { } async function toggleSuspend(): Promise { - if (!instance) throw ErrorHandling('No instance?'); + if (!instance) throw new Error('No instance?'); await os.api('admin/federation/update-instance', { host: instance.host, isSuspended: suspended, @@ -191,7 +190,7 @@ async function toggleSuspend(): Promise { } function refreshMetadata(): void { - if (!instance) throw ErrorHandling('No instance?'); + if (!instance) throw new Error('No instance?'); os.api('admin/federation/refresh-remote-instance-metadata', { host: instance.host, }); diff --git a/packages/frontend/src/pages/miauth.vue b/packages/frontend/src/pages/miauth.vue index 0a392f50a6..4df40db917 100644 --- a/packages/frontend/src/pages/miauth.vue +++ b/packages/frontend/src/pages/miauth.vue @@ -50,7 +50,6 @@ import * as os from '@/os'; import { $i, login } from '@/account'; import { i18n } from '@/i18n'; import { definePageMetadata } from '@/scripts/page-metadata'; -import { ErrorHandling } from '@/error'; const props = defineProps<{ session: string; @@ -76,7 +75,7 @@ async function accept(): Promise { state = 'accepted'; if (props.callback) { const cbUrl = new URL(props.callback); - if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw ErrorHandling('invalid url'); + if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw new Error('invalid url'); cbUrl.searchParams.set('session', props.session); location.href = cbUrl.href; } diff --git a/packages/frontend/src/pages/settings/general.vue b/packages/frontend/src/pages/settings/general.vue index 859051c406..3b39a5c00a 100644 --- a/packages/frontend/src/pages/settings/general.vue +++ b/packages/frontend/src/pages/settings/general.vue @@ -185,7 +185,6 @@ import { unisonReload } from '@/scripts/unison-reload'; import { i18n } from '@/i18n'; import { definePageMetadata } from '@/scripts/page-metadata'; import { miLocalStorage } from '@/local-storage'; -import { ErrorHandling } from '@/error'; const lang = ref(miLocalStorage.getItem('lang')); const fontSize = ref(miLocalStorage.getItem('fontSize')); @@ -277,7 +276,7 @@ function downloadEmojiIndex(lang: string) { function download() { switch (lang) { case 'en-US': return import('../../unicode-emoji-indexes/en-US.json').then(x => x.default); - default: throw ErrorHandling('unrecognized lang: ' + lang); + default: throw new Error('unrecognized lang: ' + lang); } } currentIndexes[lang] = await download(); diff --git a/packages/frontend/src/pages/settings/preferences-backups.vue b/packages/frontend/src/pages/settings/preferences-backups.vue index fb5d70af8f..eb33cbd3a4 100644 --- a/packages/frontend/src/pages/settings/preferences-backups.vue +++ b/packages/frontend/src/pages/settings/preferences-backups.vue @@ -51,8 +51,6 @@ import { i18n } from '@/i18n'; import { version, host } from '@/config'; import { definePageMetadata } from '@/scripts/page-metadata'; import { miLocalStorage } from '@/local-storage'; -import { ErrorHandling } from '@/error'; - const { t, ts } = i18n; const defaultStoreSaveKeys: (keyof typeof defaultStore['state'])[] = [ @@ -135,27 +133,27 @@ function isObject(value: unknown): value is Record { } function validate(profile: any): void { - if (!isObject(profile)) throw ErrorHandling('not an object'); + if (!isObject(profile)) throw new Error('not an object'); // Check if unnecessary properties exist - if (Object.keys(profile).some(key => !profileProps.includes(key))) throw ErrorHandling('Unnecessary properties exist'); + if (Object.keys(profile).some(key => !profileProps.includes(key))) throw new Error('Unnecessary properties exist'); - if (!profile.name) throw ErrorHandling('Missing required prop: name'); - if (!profile.misskeyVersion) throw ErrorHandling('Missing required prop: misskeyVersion'); + if (!profile.name) throw new Error('Missing required prop: name'); + if (!profile.misskeyVersion) throw new Error('Missing required prop: misskeyVersion'); // Check if createdAt and updatedAt is Date // https://zenn.dev/lollipop_onl/articles/eoz-judge-js-invalid-date - if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt as any).getTime())) throw ErrorHandling('createdAt is falsy or not Date'); + if (!profile.createdAt || Number.isNaN(new Date(profile.createdAt as any).getTime())) throw new Error('createdAt is falsy or not Date'); if (profile.updatedAt) { if (Number.isNaN(new Date(profile.updatedAt as any).getTime())) { - throw ErrorHandling('updatedAt is not Date'); + throw new Error('updatedAt is not Date'); } } else if (profile.updatedAt !== null) { - throw ErrorHandling('updatedAt is not null'); + throw new Error('updatedAt is not null'); } - if (!profile.settings) throw ErrorHandling('Missing required prop: settings'); - if (!isObject(profile.settings)) throw ErrorHandling('Invalid prop: settings'); + if (!profile.settings) throw new Error('Missing required prop: settings'); + if (!isObject(profile.settings)) throw new Error('Invalid prop: settings'); } function getSettings(): Profile['settings'] { diff --git a/packages/frontend/src/scripts/please-login.ts b/packages/frontend/src/scripts/please-login.ts index 7b63f775ac..f0eebf2242 100644 --- a/packages/frontend/src/scripts/please-login.ts +++ b/packages/frontend/src/scripts/please-login.ts @@ -22,5 +22,5 @@ export function pleaseLogin(path?: string) { }, }, 'closed'); - console.log('signin required'); + throw new Error('signin required'); } diff --git a/packages/frontend/src/scripts/time.ts b/packages/frontend/src/scripts/time.ts index 506c7a9da7..4479db1081 100644 --- a/packages/frontend/src/scripts/time.ts +++ b/packages/frontend/src/scripts/time.ts @@ -3,8 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { ErrorHandling } from '@/error'; - const dateTimeIntervals = { 'day': 86400000, 'hour': 3600000, @@ -21,7 +19,7 @@ export function dateUTC(time: number[]): Date { : time.length === 7 ? Date.UTC(time[0], time[1], time[2], time[3], time[4], time[5], time[6]) : null; - if (!d) throw ErrorHandling('wrong number of arguments'); + if (!d) throw new Error('wrong number of arguments'); return new Date(d); } diff --git a/packages/frontend/src/scripts/upload.ts b/packages/frontend/src/scripts/upload.ts index cb7ebeaffa..f5ec4b60b4 100644 --- a/packages/frontend/src/scripts/upload.ts +++ b/packages/frontend/src/scripts/upload.ts @@ -12,7 +12,6 @@ import { apiUrl } from '@/config'; import { $i } from '@/account'; import { alert } from '@/os'; import { i18n } from '@/i18n'; -import { ErrorHandling } from '@/error'; type Uploading = { id: string; @@ -35,7 +34,7 @@ export function uploadFile( name?: string, keepOriginal: boolean = defaultStore.state.keepOriginalUploading, ): Promise { - if ($i == null) console.log('Not logged in'); + if ($i == null) throw new Error('Not logged in'); if (folder && typeof folder === 'object') folder = folder.id;