improved error handling

This commit is contained in:
zadam 2023-09-21 11:16:03 +02:00
parent 5dd6f49104
commit bb81f110dd
6 changed files with 62 additions and 55 deletions

88
package-lock.json generated
View File

@ -12,7 +12,7 @@
"dependencies": { "dependencies": {
"@braintree/sanitize-url": "6.0.4", "@braintree/sanitize-url": "6.0.4",
"@electron/remote": "2.0.11", "@electron/remote": "2.0.11",
"@excalidraw/excalidraw": "0.16.0", "@excalidraw/excalidraw": "0.16.1",
"archiver": "5.3.1", "archiver": "5.3.1",
"async-mutex": "0.4.0", "async-mutex": "0.4.0",
"axios": "1.5.0", "axios": "1.5.0",
@ -22,7 +22,7 @@
"compression": "1.7.4", "compression": "1.7.4",
"cookie-parser": "1.4.6", "cookie-parser": "1.4.6",
"csurf": "1.11.0", "csurf": "1.11.0",
"dayjs": "1.11.9", "dayjs": "1.11.10",
"dayjs-plugin-utc": "0.1.2", "dayjs-plugin-utc": "0.1.2",
"debounce": "1.2.1", "debounce": "1.2.1",
"ejs": "3.1.9", "ejs": "3.1.9",
@ -70,7 +70,7 @@
"tmp": "0.2.1", "tmp": "0.2.1",
"turndown": "7.1.2", "turndown": "7.1.2",
"unescape": "1.0.1", "unescape": "1.0.1",
"ws": "8.14.1", "ws": "8.14.2",
"xml2js": "0.6.2", "xml2js": "0.6.2",
"yauzl": "2.10.0" "yauzl": "2.10.0"
}, },
@ -83,7 +83,7 @@
"electron-builder": "24.6.4", "electron-builder": "24.6.4",
"electron-packager": "17.1.2", "electron-packager": "17.1.2",
"electron-rebuild": "3.2.9", "electron-rebuild": "3.2.9",
"eslint": "8.48.0", "eslint": "8.49.0",
"eslint-config-airbnb-base": "15.0.0", "eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.0.0", "eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1", "eslint-plugin-import": "2.28.1",
@ -447,18 +447,18 @@
} }
}, },
"node_modules/@eslint/js": { "node_modules/@eslint/js": {
"version": "8.48.0", "version": "8.49.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.48.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.49.0.tgz",
"integrity": "sha512-ZSjtmelB7IJfWD2Fvb7+Z+ChTIKWq6kjda95fLcQKNS5aheVHn4IkfgRQE3sIIzTcSLwLcLZUD9UBt+V7+h+Pw==", "integrity": "sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
} }
}, },
"node_modules/@excalidraw/excalidraw": { "node_modules/@excalidraw/excalidraw": {
"version": "0.16.0", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.16.0.tgz", "resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.16.1.tgz",
"integrity": "sha512-9DGTKBWs1MPA6FbBg443Q77qGYeNJIyDWoQWVEMG2NsMfHHot8I5zM4jXvi9Eb31n8BqA1jqGhF8E9FVeprMOA==", "integrity": "sha512-4zirHk7dNx6SVq2jQmYOLliqAa1h3WPVqHM5qtJyhD769VsOqwlkopAcnZMb3G1PeIMm6cf2F31quS5MVqvoOQ==",
"peerDependencies": { "peerDependencies": {
"react": "^17.0.2 || ^18.2.0", "react": "^17.0.2 || ^18.2.0",
"react-dom": "^17.0.2 || ^18.2.0" "react-dom": "^17.0.2 || ^18.2.0"
@ -471,9 +471,9 @@
"dev": true "dev": true
}, },
"node_modules/@humanwhocodes/config-array": { "node_modules/@humanwhocodes/config-array": {
"version": "0.11.10", "version": "0.11.11",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz",
"integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "integrity": "sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@humanwhocodes/object-schema": "^1.2.1", "@humanwhocodes/object-schema": "^1.2.1",
@ -3836,9 +3836,9 @@
} }
}, },
"node_modules/dayjs": { "node_modules/dayjs": {
"version": "1.11.9", "version": "1.11.10",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.9.tgz", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz",
"integrity": "sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==" "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ=="
}, },
"node_modules/dayjs-plugin-utc": { "node_modules/dayjs-plugin-utc": {
"version": "0.1.2", "version": "0.1.2",
@ -5001,16 +5001,16 @@
} }
}, },
"node_modules/eslint": { "node_modules/eslint": {
"version": "8.48.0", "version": "8.49.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.48.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.49.0.tgz",
"integrity": "sha512-sb6DLeIuRXxeM1YljSe1KEx9/YYeZFQWcV8Rq9HfigmdDEugjLEVEa1ozDjL6YDjBpQHPJxJzze+alxi4T3OLg==", "integrity": "sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1", "@eslint-community/regexpp": "^4.6.1",
"@eslint/eslintrc": "^2.1.2", "@eslint/eslintrc": "^2.1.2",
"@eslint/js": "8.48.0", "@eslint/js": "8.49.0",
"@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/config-array": "^0.11.11",
"@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8", "@nodelib/fs.walk": "^1.2.8",
"ajv": "^6.12.4", "ajv": "^6.12.4",
@ -13124,9 +13124,9 @@
} }
}, },
"node_modules/ws": { "node_modules/ws": {
"version": "8.14.1", "version": "8.14.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.14.1.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz",
"integrity": "sha512-4OOseMUq8AzRBI/7SLMUwO+FEDnguetSk7KMb1sHwvF2w2Wv5Hoj0nlifx8vtGsftE/jWHojPy8sMMzYLJ2G/A==", "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==",
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
@ -13572,15 +13572,15 @@
} }
}, },
"@eslint/js": { "@eslint/js": {
"version": "8.48.0", "version": "8.49.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.48.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.49.0.tgz",
"integrity": "sha512-ZSjtmelB7IJfWD2Fvb7+Z+ChTIKWq6kjda95fLcQKNS5aheVHn4IkfgRQE3sIIzTcSLwLcLZUD9UBt+V7+h+Pw==", "integrity": "sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w==",
"dev": true "dev": true
}, },
"@excalidraw/excalidraw": { "@excalidraw/excalidraw": {
"version": "0.16.0", "version": "0.16.1",
"resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.16.0.tgz", "resolved": "https://registry.npmjs.org/@excalidraw/excalidraw/-/excalidraw-0.16.1.tgz",
"integrity": "sha512-9DGTKBWs1MPA6FbBg443Q77qGYeNJIyDWoQWVEMG2NsMfHHot8I5zM4jXvi9Eb31n8BqA1jqGhF8E9FVeprMOA==", "integrity": "sha512-4zirHk7dNx6SVq2jQmYOLliqAa1h3WPVqHM5qtJyhD769VsOqwlkopAcnZMb3G1PeIMm6cf2F31quS5MVqvoOQ==",
"requires": {} "requires": {}
}, },
"@gar/promisify": { "@gar/promisify": {
@ -13590,9 +13590,9 @@
"dev": true "dev": true
}, },
"@humanwhocodes/config-array": { "@humanwhocodes/config-array": {
"version": "0.11.10", "version": "0.11.11",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.11.tgz",
"integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "integrity": "sha512-N2brEuAadi0CcdeMXUkhbZB84eskAc8MEX1By6qEchoVywSgXPIjou4rYsl0V3Hj0ZnuGycGCjdNgockbzeWNA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@humanwhocodes/object-schema": "^1.2.1", "@humanwhocodes/object-schema": "^1.2.1",
@ -16215,9 +16215,9 @@
} }
}, },
"dayjs": { "dayjs": {
"version": "1.11.9", "version": "1.11.10",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.9.tgz", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz",
"integrity": "sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==" "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ=="
}, },
"dayjs-plugin-utc": { "dayjs-plugin-utc": {
"version": "0.1.2", "version": "0.1.2",
@ -17103,16 +17103,16 @@
"dev": true "dev": true
}, },
"eslint": { "eslint": {
"version": "8.48.0", "version": "8.49.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.48.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.49.0.tgz",
"integrity": "sha512-sb6DLeIuRXxeM1YljSe1KEx9/YYeZFQWcV8Rq9HfigmdDEugjLEVEa1ozDjL6YDjBpQHPJxJzze+alxi4T3OLg==", "integrity": "sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1", "@eslint-community/regexpp": "^4.6.1",
"@eslint/eslintrc": "^2.1.2", "@eslint/eslintrc": "^2.1.2",
"@eslint/js": "8.48.0", "@eslint/js": "8.49.0",
"@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/config-array": "^0.11.11",
"@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8", "@nodelib/fs.walk": "^1.2.8",
"ajv": "^6.12.4", "ajv": "^6.12.4",
@ -23120,9 +23120,9 @@
} }
}, },
"ws": { "ws": {
"version": "8.14.1", "version": "8.14.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.14.1.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz",
"integrity": "sha512-4OOseMUq8AzRBI/7SLMUwO+FEDnguetSk7KMb1sHwvF2w2Wv5Hoj0nlifx8vtGsftE/jWHojPy8sMMzYLJ2G/A==", "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==",
"requires": {} "requires": {}
}, },
"xhr": { "xhr": {

View File

@ -33,7 +33,7 @@
"dependencies": { "dependencies": {
"@braintree/sanitize-url": "6.0.4", "@braintree/sanitize-url": "6.0.4",
"@electron/remote": "2.0.11", "@electron/remote": "2.0.11",
"@excalidraw/excalidraw": "0.16.0", "@excalidraw/excalidraw": "0.16.1",
"archiver": "5.3.1", "archiver": "5.3.1",
"async-mutex": "0.4.0", "async-mutex": "0.4.0",
"axios": "1.5.0", "axios": "1.5.0",
@ -43,7 +43,7 @@
"compression": "1.7.4", "compression": "1.7.4",
"cookie-parser": "1.4.6", "cookie-parser": "1.4.6",
"csurf": "1.11.0", "csurf": "1.11.0",
"dayjs": "1.11.9", "dayjs": "1.11.10",
"dayjs-plugin-utc": "0.1.2", "dayjs-plugin-utc": "0.1.2",
"debounce": "1.2.1", "debounce": "1.2.1",
"ejs": "3.1.9", "ejs": "3.1.9",
@ -91,7 +91,7 @@
"tmp": "0.2.1", "tmp": "0.2.1",
"turndown": "7.1.2", "turndown": "7.1.2",
"unescape": "1.0.1", "unescape": "1.0.1",
"ws": "8.14.1", "ws": "8.14.2",
"xml2js": "0.6.2", "xml2js": "0.6.2",
"yauzl": "2.10.0" "yauzl": "2.10.0"
}, },
@ -101,7 +101,7 @@
"electron-builder": "24.6.4", "electron-builder": "24.6.4",
"electron-packager": "17.1.2", "electron-packager": "17.1.2",
"electron-rebuild": "3.2.9", "electron-rebuild": "3.2.9",
"eslint": "8.48.0", "eslint": "8.49.0",
"eslint-config-airbnb-base": "15.0.0", "eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.0.0", "eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1", "eslint-plugin-import": "2.28.1",

View File

@ -895,6 +895,10 @@ async function asyncPostProcessContent(note, content) {
// all keys should be replaced by the corresponding values // all keys should be replaced by the corresponding values
function replaceByMap(str, mapObj) { function replaceByMap(str, mapObj) {
if (!mapObj) {
return str;
}
const re = new RegExp(Object.keys(mapObj).join("|"),"g"); const re = new RegExp(Object.keys(mapObj).join("|"),"g");
return str.replace(re, matched => mapObj[matched]); return str.replace(re, matched => mapObj[matched]);

View File

@ -93,7 +93,7 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, password) {
return { result: 'success' }; return { result: 'success' };
} }
catch (e) { catch (e) {
log.error(`Sync failed: ${e.message}`); log.error(`Sync failed: '${e.message}', stack: ${e.stack}`);
return { return {
result: 'failure', result: 'failure',

View File

@ -71,8 +71,7 @@ async function sync() {
}; };
} }
else { else {
log.info(`sync failed: ${e.message} log.info(`Sync failed: '${e.message}', stack: ${e.stack}`);
stack: ${e.stack}`);
ws.syncFailed(); ws.syncFailed();

View File

@ -46,6 +46,10 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
} }
if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) { if (!localEC || localEC.utcDateChanged <= remoteEC.utcDateChanged) {
if (!remoteEntityRow) {
throw new Error(`Empty entity row for: ${JSON.stringify(remoteEC)}`);
}
if (remoteEC.entityName === 'blobs' && remoteEntityRow.content !== null) { if (remoteEC.entityName === 'blobs' && remoteEntityRow.content !== null) {
// we always use a Buffer object which is different from normal saving - there we use a simple string type for // we always use a Buffer object which is different from normal saving - there we use a simple string type for
// "string notes". The problem is that in general, it's not possible to detect whether a blob content // "string notes". The problem is that in general, it's not possible to detect whether a blob content
@ -59,10 +63,6 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
} }
} }
if (!remoteEntityRow) {
throw new Error(`Empty entity row for: ${JSON.stringify(remoteEC)}`);
}
sql.replace(remoteEC.entityName, remoteEntityRow); sql.replace(remoteEC.entityName, remoteEntityRow);
if (!localEC || localEC.utcDateChanged < remoteEC.utcDateChanged) { if (!localEC || localEC.utcDateChanged < remoteEC.utcDateChanged) {
@ -81,6 +81,10 @@ function updateNormalEntity(remoteEC, remoteEntityRow, instanceId) {
} }
function updateNoteReordering(remoteEC, remoteEntityRow, instanceId) { function updateNoteReordering(remoteEC, remoteEntityRow, instanceId) {
if (!remoteEntityRow) {
throw new Error(`Empty note_reordering body for: ${JSON.stringify(remoteEC)}`);
}
for (const key in remoteEntityRow) { for (const key in remoteEntityRow) {
sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [remoteEntityRow[key], key]); sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [remoteEntityRow[key], key]);
} }