mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: improve parsing quest error message
This commit is contained in:
1 parent
bb968706ad
commit
fe69841622
2 files changed
+18
-4
No files matched your search
+6
-1
@@ -38,7 +38,12 @@ async function main() {
|
|||||||
await setupTest()
|
await setupTest()
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadAndUpdateQuests()
|
try {
|
||||||
|
await loadAndUpdateQuests()
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Failed to load quests', err)
|
||||||
|
return
|
||||||
|
}
|
||||||
expiryRemovalScheduler()
|
expiryRemovalScheduler()
|
||||||
|
|
||||||
const file = await fs.readFile('./swagger.yaml', 'utf8')
|
const file = await fs.readFile('./swagger.yaml', 'utf8')
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ import logger from './logger.js'
|
|||||||
|
|
||||||
const questDirectory = path.join(process.cwd(), '..', 'quests')
|
const questDirectory = path.join(process.cwd(), '..', 'quests')
|
||||||
|
|
||||||
|
class QuestValidationError extends Error {
|
||||||
|
constructor(message, questId, error) {
|
||||||
|
super(message)
|
||||||
|
this.name = 'QuestValidationError'
|
||||||
|
this.questId = questId
|
||||||
|
this.error = error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function mapQuests(callback) {
|
async function mapQuests(callback) {
|
||||||
const questNames = await fs.readdir(questDirectory, {
|
const questNames = await fs.readdir(questDirectory, {
|
||||||
withFileTypes: true,
|
withFileTypes: true,
|
||||||
@@ -28,7 +37,7 @@ export async function loadAndUpdateQuests() {
|
|||||||
return mapQuests(async (id, questPath) => {
|
return mapQuests(async (id, questPath) => {
|
||||||
const files = await fs.readdir(questPath)
|
const files = await fs.readdir(questPath)
|
||||||
if (!files.includes('game.yml')) {
|
if (!files.includes('game.yml')) {
|
||||||
throw new Error(`Quest ${id} is missing game.yml`)
|
throw new QuestValidationError(`Missing game.yml`, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -46,8 +55,8 @@ export async function loadAndUpdateQuests() {
|
|||||||
})
|
})
|
||||||
await quest.save()
|
await quest.save()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error parsing quest ${id}:`, error)
|
logger.error(`Error parsing quest`, { id, error })
|
||||||
throw error
|
throw new QuestValidationError(`Error parsing quest`, id, error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user