1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Handle strange OneDrive sync error

This commit is contained in:
Laurent Cozic 2017-10-26 22:57:49 +01:00
parent bd8926958f
commit 2900603a8a
7 changed files with 106 additions and 22 deletions

View File

@ -616,6 +616,8 @@ class AppGui {
// URLs appear in blue.
noteTextWidget.markdownRendererOptions = {
linkUrlRenderer: (index, url) => {
if (!url) return url;
if (resourceIdRegex.test(url)) {
return url;
} else if (url.indexOf('http://') === 0 || url.indexOf('https://') === 0) {

View File

@ -5,19 +5,73 @@ const stringPadding = require('string-padding');
const cliUtils = {};
// Split a command string into an argument array
cliUtils.splitCommandString = function(s) {
s = s.replace(/--/g, '__JOP_DASH_JOP_DASH__');
s = s.replace(/-/g, '__JOP_DASH__');
let r = yargParser(s);
let output = [];
for (let i = 0; i < r._.length; i++) {
let a = r._[i].toString();
a = a.replace(/__JOP_DASH_JOP_DASH__/g, '--');
a = a.replace(/__JOP_DASH__/g, '-');
output.push(a);
cliUtils.splitCommandString = function(command) {
let args = [];
let state = "start"
let current = ""
let quote = "\""
let escapeNext = false;
for (let i = 0; i < command.length; i++) {
let c = command[i]
if (state == "quotes") {
if (c != quote) {
current += c
} else {
args.push(current)
current = ""
state = "start"
}
continue
}
if (escapeNext) {
current += c;
escapeNext = false;
continue;
}
if (c == "\\") {
escapeNext = true;
continue;
}
if (c == '"' || c == '\'') {
state = "quotes"
quote = c
continue
}
if (state == "arg") {
if (c == ' ' || c == '\t') {
args.push(current)
current = ""
state = "start"
} else {
current += c
}
continue
}
if (c != ' ' && c != "\t") {
state = "arg"
current += c
}
}
return output;
if (state == "quotes") {
throw new Error("Unclosed quote in command line: " + command)
}
if (current != "") {
args.push(current)
}
if (args.length <= 0) {
throw new Error("Empty command line")
}
return args;
}
cliUtils.printArray = function(logFunction, rows, headers = null) {

View File

@ -3892,7 +3892,7 @@
"boom": "4.3.1",
"cryptiles": "3.1.2",
"hoek": "4.2.0",
"sntp": "2.0.2"
"sntp": "2.1.0"
}
},
"hoek": {
@ -4896,9 +4896,9 @@
}
},
"sntp": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/sntp/-/sntp-2.0.2.tgz",
"integrity": "sha1-UGQRDwr4X3z9t9a2ekACjOUrSys=",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz",
"integrity": "sha512-FL1b58BDrqS3A11lJ0zEdnJ3UOKqVxawAkF3k7F0CVN7VQ34aZrV+G8BZ1WC9ZL7NyrwsW0oviwsWDgRuVYtJg==",
"requires": {
"hoek": "4.2.0"
}
@ -5771,9 +5771,9 @@
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"tkwidgets": {
"version": "0.5.14",
"resolved": "https://registry.npmjs.org/tkwidgets/-/tkwidgets-0.5.14.tgz",
"integrity": "sha512-VCb6phgm8X684mv3m3+Ylz06XwG3iNSuGgFUyxV+lcz8VU2ZTnXXeitsxCujY5t4EFL7n+Qob33+izt+S84YgA==",
"version": "0.5.15",
"resolved": "https://registry.npmjs.org/tkwidgets/-/tkwidgets-0.5.15.tgz",
"integrity": "sha512-fzxINXVK4f+Rp2fSkVoUVcF097sNQMqCrdCtiqj0Pel1aP1xU1+nQL4HGjqqrUHM30TsOQVyDu38/S70KPdsHg==",
"requires": {
"chalk": "2.3.0",
"node-emoji": "git+https://github.com/laurent22/node-emoji.git#9fa01eac463e94dde1316ef8c53089eeef4973b5",

View File

@ -55,7 +55,7 @@
"string-to-stream": "^1.1.0",
"strip-ansi": "^4.0.0",
"tcp-port-used": "^0.1.2",
"tkwidgets": "^0.5.3",
"tkwidgets": "^0.5.15",
"uuid": "^3.0.1",
"word-wrap": "^1.2.3",
"yargs-parser": "^7.0.0"

View File

@ -197,11 +197,37 @@ class FileApiDriverOneDrive {
if (!url) {
url = this.makePath_(path) + ':/delta';
query = this.itemFilter_();
const query = this.itemFilter_();
query.select += ',deleted';
}
let response = await this.api_.execJson('GET', url, query);
let response = null;
try {
response = await this.api_.execJson('GET', url, query);
} catch (error) {
if (error.code === 'resyncRequired') {
// Error: Resync required. Replace any local items with the server's version (including deletes) if you're sure that the service was up to date with your local changes when you last sync'd. Upload any local changes that the server doesn't know about.
// Code: resyncRequired
// Request: GET https://graph.microsoft.com/v1.0/drive/root:/Apps/JoplinDev:/delta?select=...
// The delta token has expired or is invalid and so a full resync is required.
// It is an error that is hard to replicate and it's not entirely clear what
// URL is in the Location header. What might happen is that:
// - OneDrive will get all the latest changes (since delta is done at the
// end of the sync process)
// - Client will get all the new files and updates from OneDrive
// This is unknown:
// - Will the files that have been deleted on OneDrive be part of the this
// URL in the Location header?
//
// More info there: https://stackoverflow.com/q/46941371/561309
url = error.headers.get('location');
response = await this.api_.execJson('GET', url, query);
} else {
throw error;
}
}
let items = [];
// The delta API might return things that happen in subdirectories of the root and we don't want to

View File

@ -46,6 +46,7 @@ class Logger {
if (object instanceof Error) {
output = object.toString();
if (object.code) output += "\nCode: " + object.code;
if (object.headers) output += "\nHeader: " + JSON.stringify(object.headers);
if (object.request) output += "\nRequest: " + object.request;
if (object.stack) output += "\n" + object.stack;
} else {

View File

@ -233,6 +233,7 @@ class OneDriveApi {
return;
} else {
error.request = method + ' ' + url + ' ' + JSON.stringify(query) + ' ' + JSON.stringify(data) + ' ' + JSON.stringify(options);
error.headers = await response.headers;
throw error;
}
}