Skip to content

Commit

Permalink
fix: display error log if game exit non 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Aug 6, 2020
1 parent fdfbf4b commit 0b91fce
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/main/app/LauncherApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export interface LauncherApp {
on(channel: 'store-ready', listener: () => void): this;
on(channel: 'minecraft-window-ready', listener: () => void): this;
on(channel: 'minecraft-start', listener: (launchOptions: { version: string; minecraft: string; forge: string; fabric: string }) => void): this;
on(channel: 'minecraft-exit', listener: (exitStatus: { code: number; signal: string; crashReport: string; crashReportLocation: string }) => void): this;
on(channel: 'minecraft-exit', listener: (exitStatus: { code: number; signal: string; crashReport: string; crashReportLocation: string; errorLog: string }) => void): this;
on(channel: 'minecraft-stdout', listener: (out: string) => void): this;
on(channel: 'minecraft-stderr', listener: (err: string) => void): this;

emit(channel: 'window-all-closed'): boolean;
emit(channel: 'store-ready'): boolean;
emit(channel: 'minecraft-window-ready', ...args: any[]): boolean;
emit(channel: 'minecraft-start', launchOptions: { version: string; minecraft: string; forge: string; fabric: string }): boolean;
emit(channel: 'minecraft-exit', exitStatus: { code: number; signal: string; crashReport: string; crashReportLocation: string }): boolean;
emit(channel: 'minecraft-exit', exitStatus: { code: number; signal: string; crashReport: string; crashReportLocation: string; errorLog: string }): boolean;
emit(channel: 'minecraft-stdout', out: string): boolean;
emit(channel: 'minecraft-stderr', err: string): boolean;
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/service/LaunchService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Exception } from '@universal/util/exception';
import { createMinecraftProcessWatcher, launch, LaunchOption, MinecraftFolder, generateArguments } from '@xmcl/core';
import { createMinecraftProcessWatcher, generateArguments, launch, LaunchOption, MinecraftFolder } from '@xmcl/core';
import { ChildProcess } from 'child_process';
import ExternalAuthSkinService from './ExternalAuthSkinService';
import { EOL } from 'os';
import DiagnoseService from './DiagnoseService';
import Service, { Inject } from './Service';
import ExternalAuthSkinService from './ExternalAuthSkinService';
import InstanceResourceService from './InstanceResourceService';
import Service, { Inject } from './Service';

export default class LaunchService extends Service {
@Inject('DiagnoseService')
Expand Down Expand Up @@ -43,8 +44,8 @@ export default class LaunchService extends Service {
gamePath: minecraftFolder.root,
resourcePath: this.state.root,
javaPath,
minMemory: instance.minMemory ? instance.minMemory : undefined,
maxMemory: instance.maxMemory ? instance.maxMemory : undefined,
minMemory: instance.minMemory && instance.minMemory > 0 ? instance.minMemory : undefined,
maxMemory: instance.maxMemory && instance.minMemory > 0 ? instance.maxMemory : undefined,
version,
extraExecOption: {
detached: true,
Expand Down Expand Up @@ -133,8 +134,8 @@ export default class LaunchService extends Service {
gamePath: minecraftFolder.root,
resourcePath: this.state.root,
javaPath,
minMemory: instance.minMemory ? instance.minMemory : undefined,
maxMemory: instance.maxMemory ? instance.maxMemory : undefined,
minMemory: instance.minMemory && instance.minMemory > 0 ? instance.minMemory : undefined,
maxMemory: instance.maxMemory && instance.minMemory > 0 ? instance.maxMemory : undefined,
version,
extraExecOption: {
detached: true,
Expand Down Expand Up @@ -171,7 +172,11 @@ export default class LaunchService extends Service {
fabric: instanceVersion.fabricLoader,
});
let watcher = createMinecraftProcessWatcher(process);
let errorLogs = [] as string[];

process.stderr?.on('data', (buf: any) => {
errorLogs.push(...buf.toString().split(EOL));
});
watcher.on('error', (err) => {
this.pushException({ type: 'launchGeneralException', error: err });
this.commit('launchStatus', 'ready');
Expand All @@ -185,6 +190,7 @@ export default class LaunchService extends Service {
signal,
crashReport,
crashReportLocation: crashReportLocation ? crashReportLocation.replace('\r\n', '').trim() : '',
errorLog: errorLogs.join('\n'),
});
this.commit('launchStatus', 'ready');
this.launchedProcess = undefined;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ p {

::-webkit-scrollbar {
width: 2px;
height: 2px;
/* remove scrollbar space */
/* background: transparent; */
/* optional: just make scrollbar invisible */
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@
"autoAlloc": "Auto Allocated",
"browse": "Browse Java executable",
"browser": "Import Java From File",
"refresh": "Refresh Local Java",
"errorDownload": "Auto-download & install failed. Please check your network condition. You can try another way.",
"incompatibleJava": "Incompatible Java",
"incompatibleJavaHint": "You can either use discovered Java 8 or download a new one!",
Expand All @@ -455,6 +454,7 @@
"noJavaInPath": "Still cannot find the java in PATH environment variable. You can try another way.",
"noLegalJava": "Cannot detect legal java for this location. Please try again.",
"noMemory": "Do not limit memory usage",
"refresh": "Refresh Local Java",
"refreshAfter": "Please Refresh After you install the java.",
"switchVersion": "Java Version Changed"
},
Expand All @@ -469,11 +469,12 @@
"client": "Client",
"crash": "Game Crashed!!",
"failed": {
"description": "There is no crash report. This this the latest log.",
"description": "There is no crash report. This this the error log and latest log.",
"general": "General Launch Failed",
"generalText": "If you encounter this several times, please contact author!",
"illegalAuth": "Illegal User Auth!",
"illegalAuthText": "Illegal user auth state! Please login or switch account to revalidate your account!",
"latest": "Latest Log",
"selectProfileEmpty": "Empty Profile",
"selectProfileEmptyText": "This is too bad. Please retry or consider recreate your launch profile. If you still encounter this, please contact author!",
"title": "Game Exited with Abnormal Code",
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/assets/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@
"checkingProblems": "检测问题中",
"crash": "游戏崩溃了!",
"failed": {
"description": "没有找到崩溃报告,这里是游戏最新日志文件",
"description": "没有找到崩溃报告,这里是游戏错误日志和最新的日志文件",
"latest": "最新日志文件",
"general": "启动失败",
"generalText": "如果你反复出现同样的问题,请联系作者!",
"illegalAuth": "用户数据为空",
Expand Down
62 changes: 42 additions & 20 deletions src/renderer/windows/main/pages/HomePageGameExitDialog.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
<template>
<v-dialog v-model="isShown" :width="550" :persistent="true">
<v-dialog
v-model="isShown"
:width="550"
:persistent="true"
>
<v-toolbar color="error">
<v-toolbar-title
class="white--text"
>
{{ isCrash ? $t('launch.crash') : $t('launch.failed.title') }}
</v-toolbar-title>
>{{ isCrash ? $t('launch.crash') : $t('launch.failed.title') }}</v-toolbar-title>
<v-spacer />
<v-toolbar-items>
<v-btn flat @click="openFolder">{{ isCrash ? $t('launch.openCrashReportFolder') : $t('launch.openLogFolder') }}</v-btn>
<v-btn
flat
@click="openFolder"
>{{ isCrash ? $t('launch.openCrashReportFolder') : $t('launch.openLogFolder') }}</v-btn>
</v-toolbar-items>
<v-btn icon @click="isShown=false">
<v-btn
icon
@click="isShown=false"
>
<v-icon>arrow_drop_down</v-icon>
</v-btn>
</v-toolbar>
<v-card>
<v-card style="overflow: auto; max-height: 450px;">
<v-card-text>
<div style="padding: 10px">{{ isCrash ? $t(`launch.crash`) : $t(`launch.failed.description`) }}</div>
<div style="min-height: 400px; max-height: 400px; overflow: auto; ">
<v-textarea
auto-grow
autofocus
box
readonly
hide-details
:value="log"
style="margin: 8px; line-height: 30px"
/>
</div>
<div
style="padding: 10px"
>{{ isCrash ? $t(`launch.crash`) : $t(`launch.failed.description`) }}</div>
<v-textarea
auto-grow
autofocus
box
readonly
hide-details
:value="errorLog"
style="margin: 8px; line-height: 30px"
/>
<div
style="padding: 10px"
>{{ $t(`launch.failed.latest`) }}</div>
<v-textarea
auto-grow
autofocus
box
readonly
hide-details
:value="log"
style="margin: 8px; line-height: 30px"
/>
</v-card-text>
</v-card>
</v-dialog>
Expand All @@ -45,6 +65,7 @@ export default defineComponent({
log: '',
isCrash: false,
crashReportLocation: '',
errorLog: '',
});
const { getLogContent, getCrashReportContent, showLog } = useInstanceLogs();
const { showItemInDirectory } = useService('BaseService');
Expand All @@ -67,8 +88,9 @@ export default defineComponent({
data.log = decorate(log);
data.isShown = true;
}
ipc.on('minecraft-exit', (event, { code, signal, crashReport, crashReportLocation }) => {
ipc.on('minecraft-exit', (event, { code, signal, crashReport, crashReportLocation, errorLog }) => {
if (code !== 0) {
data.errorLog = errorLog;
if (crashReportLocation) {
data.crashReportLocation = crashReportLocation;
data.isCrash = true;
Expand Down
18 changes: 12 additions & 6 deletions src/renderer/windows/main/pages/ResourcePackSettingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<v-container
grid-list-xs
fill-height
class="resource-pack-page"
style="overflow: auto;"
>
<v-layout
Expand Down Expand Up @@ -93,6 +94,7 @@
<div
v-else
class="list"
style="overflow-x: hidden"
>
<transition-group
name="transition-list"
Expand Down Expand Up @@ -144,6 +146,7 @@
<div
v-else
class="list"
style="overflow-x: hidden"
>
<transition-group
name="transition-list"
Expand Down Expand Up @@ -189,9 +192,7 @@
<div>
<h3
class="headline mb-0"
>
{{ $t('resourcepack.deletion', { pack: deletingPack ? deletingPack.name : '' }) }}
</h3>
>{{ $t('resourcepack.deletion', { pack: deletingPack ? deletingPack.name : '' }) }}</h3>
<div>{{ $t('resourcepack.deletionHint') }}</div>
</div>
</v-card-title>
Expand All @@ -201,9 +202,7 @@
<v-btn
flat
@click="isDeletingPack = false; deletingPack = null"
>
{{ $t('no') }}
</v-btn>
>{{ $t('no') }}</v-btn>
<v-spacer />
<v-btn
flat
Expand Down Expand Up @@ -299,4 +298,11 @@ export default defineComponent({
.card-list {
background: transparent;
}
.resource-pack-page .list::-webkit-scrollbar {
width: 0px;
height: 0px;
/* remove scrollbar space */
/* background: transparent; */
/* optional: just make scrollbar invisible */
}
</style>
2 changes: 1 addition & 1 deletion src/universal/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare module 'electron' {

on(channel: 'minecraft-window-ready', listener: (event: Electron.IpcRendererEvent) => void): this;
on(channel: 'minecraft-start', listener: (event: Electron.IpcRendererEvent) => void): this;
on(channel: 'minecraft-exit', listener: (event: Electron.IpcRendererEvent, exitStatus: { code?: number; signal?: string; crashReport?: string; crashReportLocation?: string }) => void): this;
on(channel: 'minecraft-exit', listener: (event: Electron.IpcRendererEvent, exitStatus: { code?: number; signal?: string; crashReport?: string; crashReportLocation?: string; errorLog: string }) => void): this;
on(channel: 'minecraft-stdout', listener: (event: Electron.IpcRendererEvent, out: string) => void): this;
on(channel: 'minecraft-stderr', listener: (event: Electron.IpcRendererEvent, err: string) => void): this;

Expand Down

0 comments on commit 0b91fce

Please sign in to comment.