mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +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 loadAndUpdateQuests()
|
||||
try {
|
||||
await loadAndUpdateQuests()
|
||||
} catch (err) {
|
||||
logger.error('Failed to load quests', err)
|
||||
return
|
||||
}
|
||||
expiryRemovalScheduler()
|
||||
|
||||
const file = await fs.readFile('./swagger.yaml', 'utf8')
|
||||
|
||||
@@ -7,6 +7,15 @@ import logger from './logger.js'
|
||||
|
||||
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) {
|
||||
const questNames = await fs.readdir(questDirectory, {
|
||||
withFileTypes: true,
|
||||
@@ -28,7 +37,7 @@ export async function loadAndUpdateQuests() {
|
||||
return mapQuests(async (id, questPath) => {
|
||||
const files = await fs.readdir(questPath)
|
||||
if (!files.includes('game.yml')) {
|
||||
throw new Error(`Quest ${id} is missing game.yml`)
|
||||
throw new QuestValidationError(`Missing game.yml`, id)
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -46,8 +55,8 @@ export async function loadAndUpdateQuests() {
|
||||
})
|
||||
await quest.save()
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing quest ${id}:`, error)
|
||||
throw error
|
||||
logger.error(`Error parsing quest`, { id, error })
|
||||
throw new QuestValidationError(`Error parsing quest`, id, error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user