Error handling (#121)

This commit is contained in:
Geometrically
2023-05-22 18:11:31 -07:00
committed by GitHub
parent 6014172046
commit 1b47eb71e1
36 changed files with 271 additions and 198 deletions

View File

@@ -1,6 +1,5 @@
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import { ofetch } from 'ofetch'
import {
Pagination,
Checkbox,
@@ -18,7 +17,7 @@ import {
Promotion,
} from 'omorphia'
import Multiselect from 'vue-multiselect'
import { useSearch } from '@/store/state'
import { handleError, useSearch } from '@/store/state'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import { get_categories, get_loaders, get_game_versions } from '@/helpers/tags'
import { useRoute } from 'vue-router'
@@ -28,6 +27,7 @@ import InstanceInstallModal from '@/components/ui/InstanceInstallModal.vue'
import SplashScreen from '@/components/ui/SplashScreen.vue'
import Instance from '@/components/ui/Instance.vue'
import IncompatibilityWarningModal from '@/components/ui/IncompatibilityWarningModal.vue'
import { useFetch } from '@/helpers/fetch.js'
const route = useRoute()
@@ -64,9 +64,9 @@ if (searchStore.projectType === 'modpack') {
onMounted(async () => {
;[categories.value, loaders.value, availableGameVersions.value] = await Promise.all([
get_categories(),
get_loaders(),
get_game_versions(),
get_categories().catch(handleError),
get_loaders().catch(handleError),
get_game_versions().catch(handleError),
])
breadcrumbs.setContext({ name: 'Browse', link: route.path })
if (searchStore.projectType === 'modpack') {
@@ -94,7 +94,10 @@ const sortedCategories = computed(() => {
const getSearchResults = async () => {
const queryString = searchStore.getQueryString()
const response = await ofetch(`https://api.modrinth.com/v2/search${queryString}`)
const response = await useFetch(
`https://api.modrinth.com/v2/search${queryString}`,
'search results'
)
searchStore.setSearchResults(response)
}

View File

@@ -1,11 +1,12 @@
<script setup>
import { ref, onUnmounted, shallowRef } from 'vue'
import { ofetch } from 'ofetch'
import { useRoute } from 'vue-router'
import RowDisplay from '@/components/RowDisplay.vue'
import { list } from '@/helpers/profile.js'
import { profile_listener } from '@/helpers/events'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import { useFetch } from '@/helpers/fetch.js'
import { handleError } from '@/store/notifications.js'
const featuredModpacks = ref({})
const featuredMods = ref({})
@@ -20,7 +21,7 @@ const recentInstances = shallowRef([])
const getInstances = async () => {
filter.value = ''
const profiles = await list(true)
const profiles = await list(true).catch(handleError)
recentInstances.value = Object.values(profiles)
const excludeIds = recentInstances.value.map((i) => i.metadata?.linked_data?.project_id)
@@ -31,14 +32,16 @@ const getInstances = async () => {
}
const getFeaturedModpacks = async () => {
const response = await ofetch(
`https://api.modrinth.com/v2/search?facets=[["project_type:modpack"]]&limit=10&index=follows&filters=${filter.value}`
const response = await useFetch(
`https://api.modrinth.com/v2/search?facets=[["project_type:modpack"]]&limit=10&index=follows&filters=${filter.value}`,
'featured modpacks'
)
featuredModpacks.value = response.hits
}
const getFeaturedMods = async () => {
const response = await ofetch(
`https://api.modrinth.com/v2/search?facets=[["project_type:mod"]]&limit=10&index=follows&filters=${filter.value}`
const response = await useFetch(
`https://api.modrinth.com/v2/search?facets=[["project_type:mod"]]&limit=10&index=follows&filters=${filter.value}`,
'featured mods'
)
featuredMods.value = response.hits
}

View File

@@ -5,17 +5,18 @@ import { list } from '@/helpers/profile.js'
import { useRoute } from 'vue-router'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import { profile_listener } from '@/helpers/events.js'
import { handleError } from '@/store/notifications.js'
const route = useRoute()
const breadcrumbs = useBreadcrumbs()
breadcrumbs.setRootContext({ name: 'Library', link: route.path })
const profiles = await list(true)
const profiles = await list(true).catch(handleError)
const instances = shallowRef(Object.values(profiles))
const unlisten = await profile_listener(async () => {
const profiles = await list(true)
const profiles = await list(true).catch(handleError)
instances.value = Object.values(profiles)
})
onUnmounted(() => unlisten())

View File

@@ -1,14 +1,14 @@
<script setup>
import { ref, watch } from 'vue'
import { Card, Slider, DropdownSelect, Toggle } from 'omorphia'
import { useTheming } from '@/store/state'
import { handleError, useTheming } from '@/store/state'
import { get, set } from '@/helpers/settings'
import { get_max_memory } from '@/helpers/jre'
import JavaSelector from '@/components/ui/JavaSelector.vue'
const themeStore = useTheming()
const fetchSettings = await get()
const fetchSettings = await get().catch(handleError)
if (!fetchSettings.java_globals?.JAVA_8)
fetchSettings.java_globals.JAVA_8 = { path: '', version: '' }
@@ -19,7 +19,7 @@ fetchSettings.javaArgs = fetchSettings.custom_java_args.join(' ')
fetchSettings.envArgs = fetchSettings.custom_env_args.map((x) => x.join('=')).join(' ')
const settings = ref(fetchSettings)
const maxMemory = ref((await get_max_memory()) / 1024)
const maxMemory = ref((await get_max_memory().catch(handleError)) / 1024)
watch(settings.value, async (oldSettings, newSettings) => {
if (newSettings.java_globals?.JAVA_8?.path === '') {

View File

@@ -50,7 +50,7 @@
</Button>
<!--TODO: https://github.com/tauri-apps/tauri/issues/4062 -->
<Button class="instance-button" icon-only @click="open({ defaultPath: instance.path })">
<OpenFolderIcon />
<FolderOpenIcon />
</Button>
</span>
</Card>
@@ -82,8 +82,18 @@
</div>
</template>
<script setup>
import { BoxIcon, SettingsIcon, FileIcon, XIcon, Button, Avatar, Card, Promotion } from 'omorphia'
import { PlayIcon, OpenFolderIcon } from '@/assets/icons'
import {
BoxIcon,
SettingsIcon,
FileIcon,
XIcon,
Button,
Avatar,
Card,
Promotion,
PlayIcon,
FolderOpenIcon,
} from 'omorphia'
import { get, run } from '@/helpers/profile'
import {
get_all_running_profile_paths,
@@ -95,13 +105,13 @@ import { useRoute } from 'vue-router'
import { ref, onUnmounted } from 'vue'
import { convertFileSrc } from '@tauri-apps/api/tauri'
import { open } from '@tauri-apps/api/dialog'
import { useBreadcrumbs, useLoading, useSearch } from '@/store/state'
import { handleError, useBreadcrumbs, useLoading, useSearch } from '@/store/state'
const route = useRoute()
const searchStore = useSearch()
const breadcrumbs = useBreadcrumbs()
const instance = ref(await get(route.params.id))
const instance = ref(await get(route.params.id).catch(handleError))
searchStore.instanceContext = instance.value
breadcrumbs.setName('Instance', instance.value.metadata.name)
@@ -118,13 +128,13 @@ const loading = ref(false)
const startInstance = async () => {
loading.value = true
uuid.value = await run(route.params.id)
uuid.value = await run(route.params.id).catch(handleError)
loading.value = false
playing.value = true
}
const checkProcess = async () => {
const runningPaths = await get_all_running_profile_paths()
const runningPaths = await get_all_running_profile_paths().catch(handleError)
if (runningPaths.includes(instance.value.path)) {
playing.value = true
return
@@ -141,10 +151,10 @@ const stopInstance = async () => {
try {
if (!uuid.value) {
const uuids = await get_uuids_by_profile_path(instance.value.path)
const uuids = await get_uuids_by_profile_path(instance.value.path).catch(handleError)
uuid.value = uuids[0] // populate Uuid to listen for in the process_listener
uuids.forEach(async (u) => await kill_by_uuid(u))
} else await kill_by_uuid(uuid.value)
uuids.forEach(async (u) => await kill_by_uuid(u).catch(handleError))
} else await kill_by_uuid(uuid.value).catch(handleError)
} catch (err) {
// Theseus currently throws:
// "Error launching Minecraft: Minecraft exited with non-zero code 1" error
@@ -155,7 +165,7 @@ const stopInstance = async () => {
const unlistenProfiles = await profile_listener(async (event) => {
if (event.path === route.params.id) {
instance.value = await get(route.params.id)
instance.value = await get(route.params.id).catch(handleError)
}
})

View File

@@ -55,6 +55,7 @@ import calendar from 'dayjs/plugin/calendar'
import { get_stdout_by_uuid, get_uuids_by_profile_path } from '@/helpers/process.js'
import { useRoute } from 'vue-router'
import { process_listener } from '@/helpers/events.js'
import { handleError } from '@/store/notifications.js'
dayjs.extend(calendar)
@@ -68,19 +69,19 @@ const props = defineProps({
})
async function getLiveLog() {
const uuids = await get_uuids_by_profile_path(route.params.id)
const uuids = await get_uuids_by_profile_path(route.params.id).catch(handleError)
let returnValue
if (uuids.length === 0) {
returnValue = 'No live game detected. \nStart your game to proceed'
} else {
returnValue = await get_stdout_by_uuid(uuids[0])
returnValue = await get_stdout_by_uuid(uuids[0]).catch(handleError)
}
return { name: 'Live Log', stdout: returnValue, live: true }
}
async function getLogs() {
return (await get_logs(props.instance.uuid, true)).reverse().map((log) => {
return (await get_logs(props.instance.uuid, true).catch(handleError)).reverse().map((log) => {
log.name = dayjs(
log.datetime_string.slice(0, 8) + 'T' + log.datetime_string.slice(9)
).calendar()
@@ -116,7 +117,7 @@ watch(selectedLogIndex, async (newIndex) => {
logs.value[newIndex].stdout = await get_stdout_by_datetime(
props.instance.uuid,
logs.value[newIndex].datetime_string
)
).catch(handleError)
}
})
@@ -124,7 +125,10 @@ const deleteLog = async () => {
if (logs.value[selectedLogIndex.value] && selectedLogIndex.value !== 0) {
let deleteIndex = selectedLogIndex.value
selectedLogIndex.value = deleteIndex - 1
await delete_logs_by_datetime(props.instance.uuid, logs.value[deleteIndex].datetime_string)
await delete_logs_by_datetime(
props.instance.uuid,
logs.value[deleteIndex].datetime_string
).catch(handleError)
await setLogs()
}
}

View File

@@ -92,6 +92,7 @@ import {
update_all,
update_project,
} from '@/helpers/profile.js'
import { handleError } from '@/store/notifications.js'
const router = useRouter()
@@ -200,7 +201,7 @@ async function updateAll() {
}
}
const paths = await update_all(props.instance.path)
const paths = await update_all(props.instance.path).catch(handleError)
for (const [oldVal, newVal] of Object.entries(paths)) {
const index = projects.value.findIndex((x) => x.path === oldVal)
@@ -219,7 +220,7 @@ async function updateAll() {
async function updateProject(mod) {
mod.updating = true
mod.path = await update_project(props.instance.path, mod.path)
mod.path = await update_project(props.instance.path, mod.path).catch(handleError)
mod.updating = false
mod.outdated = false
@@ -228,11 +229,11 @@ async function updateProject(mod) {
}
async function toggleDisableMod(mod) {
mod.path = await toggle_disable_project(props.instance.path, mod.path)
mod.path = await toggle_disable_project(props.instance.path, mod.path).catch(handleError)
}
async function removeMod(mod) {
await remove_project(props.instance.path, mod.path)
await remove_project(props.instance.path, mod.path).catch(handleError)
projects.value = projects.value.filter((x) => mod.path !== x.path)
}
</script>

View File

@@ -217,8 +217,8 @@ import {
DropdownSelect,
XIcon,
SaveIcon,
HammerIcon,
} from 'omorphia'
import { HammerIcon } from '@/assets/icons'
import { useRouter } from 'vue-router'
import { edit, edit_icon, get_optimal_jre_key, install, remove } from '@/helpers/profile.js'
import { computed, readonly, ref, shallowRef, watch } from 'vue'
@@ -229,6 +229,7 @@ import { convertFileSrc } from '@tauri-apps/api/tauri'
import { open } from '@tauri-apps/api/dialog'
import { get_fabric_versions, get_forge_versions, get_quilt_versions } from '@/helpers/metadata.js'
import { get_game_versions, get_loaders } from '@/helpers/tags.js'
import { handleError } from '@/store/notifications.js'
const router = useRouter()
@@ -244,7 +245,7 @@ const icon = ref(props.instance.metadata.icon)
async function resetIcon() {
icon.value = null
await edit_icon(props.instance.path, null)
await edit_icon(props.instance.path, null).catch(handleError)
}
async function setIcon() {
@@ -261,15 +262,15 @@ async function setIcon() {
if (!value) return
icon.value = value
await edit_icon(props.instance.path, icon.value)
await edit_icon(props.instance.path, icon.value).catch(handleError)
}
const globalSettings = await get()
const globalSettings = await get().catch(handleError)
const javaSettings = props.instance.java ?? {}
const overrideJavaInstall = ref(!!javaSettings.override_version)
const optimalJava = readonly(await get_optimal_jre_key(props.instance.path))
const optimalJava = readonly(await get_optimal_jre_key(props.instance.path).catch(handleError))
const javaInstall = ref(optimalJava ?? javaSettings.override_version ?? { path: '', version: '' })
const overrideJavaArgs = ref(!!javaSettings.extra_arguments)
@@ -282,7 +283,7 @@ const envVars = ref(
const overrideMemorySettings = ref(!!props.instance.memory)
const memory = ref(props.instance.memory ?? globalSettings.memory)
const maxMemory = (await get_max_memory()) / 1024
const maxMemory = (await get_max_memory().catch(handleError)) / 1024
const overrideWindowSettings = ref(!!props.instance.resolution)
const resolution = ref(props.instance.resolution ?? globalSettings.game_resolution)
@@ -356,14 +357,14 @@ const repairing = ref(false)
async function repairProfile() {
repairing.value = true
await install(props.instance.path)
await install(props.instance.path).catch(handleError)
repairing.value = false
}
const removing = ref(false)
async function removeProfile() {
removing.value = true
await remove(props.instance.path)
await remove(props.instance.path).catch(handleError)
removing.value = false
await router.push({ path: '/' })
@@ -374,17 +375,18 @@ const showSnapshots = ref(false)
const [fabric_versions, forge_versions, quilt_versions, all_game_versions, loaders] =
await Promise.all([
get_fabric_versions().then(shallowRef),
get_forge_versions().then(shallowRef),
get_quilt_versions().then(shallowRef),
get_game_versions().then(shallowRef),
get_fabric_versions().then(shallowRef).catch(handleError),
get_forge_versions().then(shallowRef).catch(handleError),
get_quilt_versions().then(shallowRef).catch(handleError),
get_game_versions().then(shallowRef).catch(handleError),
get_loaders()
.then((value) =>
value
.filter((item) => item.supported_project_types.includes('modpack'))
.map((item) => item.name.toLowerCase())
)
.then(ref),
.then(ref)
.catch(handleError),
])
loaders.value.push('vanilla')
@@ -449,7 +451,7 @@ async function saveGvLoaderEdits() {
if (loader.value !== 'vanilla') {
editProfile.metadata.loader_version = selectableLoaderVersions.value[loaderVersionIndex.value]
}
await edit(props.instance.path, editProfile)
await edit(props.instance.path, editProfile).catch(handleError)
await repairProfile()
editing.value = false

View File

@@ -240,7 +240,6 @@ import { install as packInstall } from '@/helpers/pack'
import { list, add_project_from_version as installMod, check_installed } from '@/helpers/profile'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { ofetch } from 'ofetch'
import { useRoute, useRouter } from 'vue-router'
import { ref, shallowRef, watch } from 'vue'
import { installVersionDependencies } from '@/helpers/utils'
@@ -250,6 +249,8 @@ import Instance from '@/components/ui/Instance.vue'
import { useSearch } from '@/store/search'
import { useBreadcrumbs } from '@/store/breadcrumbs'
import IncompatibilityWarningModal from '@/components/ui/IncompatibilityWarningModal.vue'
import { useFetch } from '@/helpers/fetch.js'
import { handleError } from '@/store/notifications.js'
const searchStore = useSearch()
@@ -264,15 +265,23 @@ const instance = ref(searchStore.instanceContext)
const installing = ref(false)
const [data, versions, members, dependencies, categories, loaders] = await Promise.all([
ofetch(`https://api.modrinth.com/v2/project/${route.params.id}`).then(shallowRef),
ofetch(`https://api.modrinth.com/v2/project/${route.params.id}/version`).then(shallowRef),
ofetch(`https://api.modrinth.com/v2/project/${route.params.id}/members`).then(shallowRef),
ofetch(`https://api.modrinth.com/v2/project/${route.params.id}/dependencies`).then(shallowRef),
get_loaders().then(ref),
get_categories().then(ref),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}`, 'project').then(shallowRef),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/version`, 'project').then(
shallowRef
),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/members`, 'project').then(
shallowRef
),
useFetch(`https://api.modrinth.com/v2/project/${route.params.id}/dependencies`, 'project').then(
shallowRef
),
get_loaders().then(ref).catch(handleError),
get_categories().then(ref).catch(handleError),
])
const installed = ref(instance.value && (await check_installed(instance.value.path, data.value.id)))
const installed = ref(
instance.value && (await check_installed(instance.value.path, data.value.id).catch(handleError))
)
breadcrumbs.setName('Project', data.value.title)
@@ -306,14 +315,16 @@ async function install(version) {
}
if (data.value.project_type === 'modpack') {
const packs = Object.values(await list(true))
const packs = Object.values(await list(true).catch(handleError))
if (
packs.length === 0 ||
!packs
.map((value) => value.metadata)
.find((pack) => pack.linked_data?.project_id === data.value.id)
) {
await packInstall(queuedVersionData.id, data.value.title, data.value.icon_url)
await packInstall(queuedVersionData.id, data.value.title, data.value.icon_url).catch(
handleError
)
} else {
confirmModal.value.show(queuedVersionData.id, data.value.title, data.value.icon_url)
}
@@ -340,7 +351,7 @@ async function install(version) {
return
} else {
queuedVersionData = selectedVersion
await installMod(instance.value.path, selectedVersion.id)
await installMod(instance.value.path, selectedVersion.id).catch(handleError)
installVersionDependencies(instance.value, queuedVersionData)
}
} else {
@@ -354,7 +365,7 @@ async function install(version) {
: true)
)
if (compatible) {
await installMod(instance.value.path, queuedVersionData.id)
await installMod(instance.value.path, queuedVersionData.id).catch(handleError)
await installVersionDependencies(instance.value, queuedVersionData)
} else {
incompatibilityWarning.value.show(