change exit code; make enum for exit code

This commit is contained in:
geekgeekrun
2024-03-11 07:03:11 +08:00
parent 6ce92af189
commit 55cc92a498
4 changed files with 20 additions and 10 deletions

View File

@@ -17,10 +17,15 @@ const initPlugins = (hooks) => {
new DingtalkPlugin(dingTalkAccessToken).apply(hooks)
}
const AUTO_CHAT_ERROR_EXIT_CODE = {
COOKIE_INVALID: 81,
LOGIN_STATUS_INVALID: 82
}
;(async () => {
if (!bossCookies?.length) {
console.error('There is no cookies. You can save a copy with EditThisCookie extension.')
process.exit(1)
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.COOKIE_INVALID)
}
const hooks = {
puppeteerLaunched: new SyncHook(),
@@ -39,7 +44,7 @@ const initPlugins = (hooks) => {
} catch (err) {
console.log(err)
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
process.exit(2)
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID)
break
}
await sleep(3000)

View File

@@ -5,8 +5,7 @@ import { pipeWriteRegardlessError } from '../utils/pipe'
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
export enum DOWNLOAD_ERROR_EXIT_CODE {
NO_ERROR = 0,
DOWNLOAD_ERROR = 1
DOWNLOAD_ERROR = 80
}
export const checkAndDownloadDependenciesForInit = async () => {
@@ -84,7 +83,7 @@ export const checkAndDownloadDependenciesForInit = async () => {
})
await promiseWithResolver.promise
app.exit(DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR)
app.exit()
} catch (err) {
console.error(err)
pipeWriteRegardlessError(

View File

@@ -7,6 +7,11 @@ import { pipeWriteRegardlessError } from '../utils/pipe'
import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
export enum AUTO_CHAT_ERROR_EXIT_CODE {
PUPPETEER_IS_NOT_EXECUTABLE = 81,
LOGIN_STATUS_INVALID = 82
}
const { groupRobotAccessToken: dingTalkAccessToken } = readConfigFile('dingtalk.json')
const initPlugins = (hooks) => {
@@ -47,13 +52,13 @@ export const runAutoChat = async () => {
)
} catch (err) {
console.error(err)
app.exit(1)
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
return
}
const isPuppeteerExecutable = !!(await getAnyAvailablePuppeteerExecutable())
if (!isPuppeteerExecutable) {
app.exit(1)
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
return
}
@@ -90,7 +95,7 @@ export const runAutoChat = async () => {
} catch (err) {
console.log(err)
if (err instanceof Error && err.message.includes('LOGIN_STATUS_INVALID')) {
process.exit(2)
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID)
break
}
await sleep(3000)

View File

@@ -16,6 +16,7 @@ import { checkCookieListFormat } from '../../common/utils/cookie'
import { getAnyAvailablePuppeteerExecutable } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable/index'
import { DOWNLOAD_ERROR_EXIT_CODE } from '../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index'
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
import { AUTO_CHAT_ERROR_EXIT_CODE } from '../flow/GEEK_AUTO_START_CHAT_WITH_BOSS'
let mainWindow: BrowserWindow | null = null
export function createMainWindow(): void {
@@ -151,7 +152,7 @@ export function createMainWindow(): void {
subProcessOfPuppeteer!.once('exit', (exitCode) => {
subProcessOfPuppeteer = null
if (exitCode === 1) {
if (exitCode === AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE) {
// means cannot find downloaded puppeteer
reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
} else {
@@ -211,7 +212,7 @@ export function createMainWindow(): void {
)
subProcessOfCheckAndDownloadDependencies!.once('exit', (exitCode) => {
switch (exitCode) {
case DOWNLOAD_ERROR_EXIT_CODE.NO_ERROR: {
case 0: {
resolve(exitCode)
break
}