Skip to content

Commit 1903ad8

Browse files
committed
Added command showing imported notes errors
1 parent 451dbf4 commit 1903ad8

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# TODO
22

3-
- Добавить команду для вывода импортированных заметок с ошибками
43
- Добавить команду повторного импорта заметок с ошибками

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getImportNotesStatus, importNotes } from './src/notes_importer.js'
1+
import { getImportedNotesErrors, getImportedNotesStatus, importNotes } from './src/notes_importer.js'
22
import { cleanDb } from './src/db.js'
33

44
await main()
@@ -20,6 +20,9 @@ async function main() {
2020
case '--clean-db':
2121
await cleanDb()
2222
return
23+
case '--show-errors':
24+
await showErrors()
25+
return
2326
default:
2427
printHelp()
2528
}
@@ -33,8 +36,15 @@ function printHelp() {
3336
}
3437

3538
async function printStatus(notesDir) {
36-
const { importedCount, notesCount, importedWithErrorsCount, importedWithoutErrorsCount, progress } = await getImportNotesStatus(notesDir)
39+
const { importedCount, notesCount, importedWithErrorsCount, importedWithoutErrorsCount, progress } = await getImportedNotesStatus(notesDir)
3740
console.info(`Imported: ${importedCount}/${notesCount} [${progress}%]`)
3841
console.info(`Imported with errors: ${importedWithErrorsCount}`)
3942
console.info(`Imported without errors: ${importedWithoutErrorsCount}`)
4043
}
44+
45+
async function showErrors() {
46+
(await getImportedNotesErrors()).forEach((noteStatus, index) => {
47+
console.log(`${index + 1}. "${noteStatus.filePath}":`)
48+
console.log(`${noteStatus.error?.message || noteStatus.error}\n`)
49+
})
50+
}

src/notes_importer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function saveNoteToNotion(noteInfo) {
9595
return noteInfo
9696
}
9797

98-
export async function getImportNotesStatus(notesDir) {
98+
export async function getImportedNotesStatus(notesDir) {
9999
const notesCount = getNotesFiles(notesDir).filesAndDirs.length
100100
const importedNotes = await loadImportStatuses()
101101
const importedCount = importedNotes.length
@@ -110,3 +110,7 @@ export async function getImportNotesStatus(notesDir) {
110110
progress: Math.round(importedCount / notesCount * 100)
111111
}
112112
}
113+
114+
export async function getImportedNotesErrors() {
115+
return (await loadImportStatuses()).filter(it => it.error)
116+
}

0 commit comments

Comments
 (0)