Skip to content

Commit 4851f10

Browse files
committed
fix: Introduce proper XbelParseError
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 02d3509 commit 4851f10

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
"Error046": {
138138
"message": "E046: Invalid URL. `{0}` is not a valid URL."
139139
},
140+
"Error047": {
141+
"message": "E047: Failed to parse XBEL file. The XBEL data seems to be corrupted or incomplete. You can try removing the file on the server to let floccus recreate it. Make sure to take a backup first."
142+
},
140143
"LabelWebdavurl": {
141144
"message": "WebDAV URL"
142145
},

src/errors/Error.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,12 @@ export class InvalidUrlError extends FloccusError {
403403
this.url = url
404404
Object.setPrototypeOf(this, InvalidUrlError.prototype)
405405
}
406+
}
407+
408+
export class XbelParseError extends FloccusError {
409+
constructor() {
410+
super(`E047: Failed to parse XBEL file. The XBEL data seems to be corrupted or incomplete. You can try removing the file on the server to let floccus recreate it. Make sure to take a backup first.`)
411+
this.code = 47
412+
Object.setPrototypeOf(this, XbelParseError.prototype)
413+
}
406414
}

src/lib/serializers/Xbel.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Serializer from '../interfaces/Serializer'
22
import { Bookmark, Folder, ItemLocation } from '../Tree'
33
import { XMLParser, XMLBuilder } from 'fast-xml-parser'
44
import Logger from '../Logger'
5+
import { XbelParseError } from '../../errors/Error'
56

67
class XbelSerializer implements Serializer {
78
serialize(folder: Folder<typeof ItemLocation.SERVER>) {
@@ -22,22 +23,19 @@ class XbelSerializer implements Serializer {
2223
xmlObj = parser.parse(xbel)
2324
} catch (e) {
2425
Logger.log('Parse Error: ' + e.message)
25-
throw new Error('Parse Error: ' + e.message)
26+
throw new XbelParseError()
2627
}
2728

2829
if (!Array.isArray(xmlObj[0].xbel)) {
29-
throw new Error(
30-
'Parse Error: ' + xbel
31-
)
30+
throw new XbelParseError()
3231
}
3332

3433
const rootFolder = new Folder({ id: 0, title: 'root', location: ItemLocation.SERVER })
3534
try {
3635
this._parseFolder(xmlObj[0].xbel, rootFolder)
3736
} catch (e) {
38-
throw new Error(
39-
'Parse Error: ' + e.message
40-
)
37+
Logger.log('Parse Error: ' + e.message)
38+
throw new XbelParseError()
4139
}
4240
return rootFolder
4341
}

0 commit comments

Comments
 (0)