From e9ba519db39ca30e67bce1a687dd2069d33e384a Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sat, 23 Jun 2018 23:30:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/getPatchmanifest.ts | 2 +- src/ssn/getSolidpkg.ts | 8 ++++---- src/ssn/readSsnFile.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ssn/getPatchmanifest.ts b/src/ssn/getPatchmanifest.ts index 6d012df..1e9529b 100644 --- a/src/ssn/getPatchmanifest.ts +++ b/src/ssn/getPatchmanifest.ts @@ -14,7 +14,7 @@ const Decoder = new TextDecoder('utf-8'); export default async function getPatchmanifest(product: Product): Promise { //Verify function arguments if (!verifyProductName(product)) { - throw new Error(`"${product}" is not a valid product.`); + throw new TypeError(`"${product}" is not a valid product.`); } //Download .patchmanifest file diff --git a/src/ssn/getSolidpkg.ts b/src/ssn/getSolidpkg.ts index a4917d4..a31d1fc 100644 --- a/src/ssn/getSolidpkg.ts +++ b/src/ssn/getSolidpkg.ts @@ -11,16 +11,16 @@ import verifySolidpkg from './verifySolidpkg'; export default async function getSolidpkg(product: Product, from: number, to: number): Promise { //Verify function arguments if (!verifyProductName(product)) { - throw new Error(`"${product}" is not a valid product.`); + throw new TypeError(`"${product}" is not a valid product.`); } if (typeof from !== 'number' || (from | 0) !== from || from < -1) { - throw new Error(`from must be an integer greater than or equal to -1 but it is "${from}"`); + throw new TypeError(`from must be an integer greater than or equal to -1 but it is "${from}"`); } if (typeof to !== 'number' || (to | 0) !== to || to < 0) { - throw new Error(`to must be an integer greater than or equal to 0 but it is "${to}"`); + throw new TypeError(`to must be an integer greater than or equal to 0 but it is "${to}"`); } if (from >= to) { - throw new Error(`from must be less than to but "${from}" is not less than "${to}".`); + throw new TypeError(`from must be less than to but "${from}" is not less than "${to}".`); } //Download .solidpkg file diff --git a/src/ssn/readSsnFile.ts b/src/ssn/readSsnFile.ts index ad630fb..dfae703 100644 --- a/src/ssn/readSsnFile.ts +++ b/src/ssn/readSsnFile.ts @@ -136,9 +136,9 @@ export default function readSsnFile(buffer: ArrayBuffer): ISsnFileEntry[] { //skip 20 bytes: hash of new file pos += 40; break; - default: - //unknown field, ignore it + default: //unknown field pos += fieldLength; + throw new Error(`Unknown entry in SSN extra field: id "${fieldId}", length "${fieldLength}"`); } } pos += fileCommentLength;