cacth error when reading archive

This commit is contained in:
Jan Prochazka 2022-06-12 09:16:10 +02:00
parent 13b549ca2c
commit 44827ea504

View File

@ -1,11 +1,8 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const stream = require('stream');
const readline = require('readline'); const readline = require('readline');
const path = require('path'); const path = require('path');
const { formatWithOptions } = require('util');
const { archivedir, clearArchiveLinksCache, resolveArchiveFolder } = require('../utility/directories'); const { archivedir, clearArchiveLinksCache, resolveArchiveFolder } = require('../utility/directories');
const socket = require('../utility/socket'); const socket = require('../utility/socket');
const JsonLinesDatastore = require('../utility/JsonLinesDatastore');
const { saveFreeTableData } = require('../utility/freeTableStorage'); const { saveFreeTableData } = require('../utility/freeTableStorage');
const loadFilesRecursive = require('../utility/loadFilesRecursive'); const loadFilesRecursive = require('../utility/loadFilesRecursive');
@ -45,29 +42,34 @@ module.exports = {
files_meta: true, files_meta: true,
async files({ folder }) { async files({ folder }) {
const dir = resolveArchiveFolder(folder); try {
if (!(await fs.exists(dir))) return []; const dir = resolveArchiveFolder(folder);
const files = await loadFilesRecursive(dir); // fs.readdir(dir); if (!(await fs.exists(dir))) return [];
const files = await loadFilesRecursive(dir); // fs.readdir(dir);
function fileType(ext, type) { function fileType(ext, type) {
return files return files
.filter(name => name.endsWith(ext)) .filter(name => name.endsWith(ext))
.map(name => ({ .map(name => ({
name: name.slice(0, -ext.length), name: name.slice(0, -ext.length),
label: path.parse(name.slice(0, -ext.length)).base, label: path.parse(name.slice(0, -ext.length)).base,
type, type,
})); }));
}
return [
...fileType('.jsonl', 'jsonl'),
...fileType('.table.yaml', 'table.yaml'),
...fileType('.view.sql', 'view.sql'),
...fileType('.proc.sql', 'proc.sql'),
...fileType('.func.sql', 'func.sql'),
...fileType('.trigger.sql', 'trigger.sql'),
...fileType('.matview.sql', 'matview.sql'),
];
} catch (err) {
console.log('Error reading archive files', err.message);
return [];
} }
return [
...fileType('.jsonl', 'jsonl'),
...fileType('.table.yaml', 'table.yaml'),
...fileType('.view.sql', 'view.sql'),
...fileType('.proc.sql', 'proc.sql'),
...fileType('.func.sql', 'func.sql'),
...fileType('.trigger.sql', 'trigger.sql'),
...fileType('.matview.sql', 'matview.sql'),
];
}, },
refreshFiles_meta: true, refreshFiles_meta: true,