🎨 Improve error handling
This commit is contained in:
parent
16fb98e1aa
commit
e9ba519db3
3 changed files with 7 additions and 7 deletions
|
@ -14,7 +14,7 @@ const Decoder = new TextDecoder('utf-8');
|
||||||
export default async function getPatchmanifest(product: Product): Promise<IManifest> {
|
export default async function getPatchmanifest(product: Product): Promise<IManifest> {
|
||||||
//Verify function arguments
|
//Verify function arguments
|
||||||
if (!verifyProductName(product)) {
|
if (!verifyProductName(product)) {
|
||||||
throw new Error(`"${product}" is not a valid product.`);
|
throw new TypeError(`"${product}" is not a valid product.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Download .patchmanifest file
|
//Download .patchmanifest file
|
||||||
|
|
|
@ -11,16 +11,16 @@ import verifySolidpkg from './verifySolidpkg';
|
||||||
export default async function getSolidpkg(product: Product, from: number, to: number): Promise<ISolidSimple> {
|
export default async function getSolidpkg(product: Product, from: number, to: number): Promise<ISolidSimple> {
|
||||||
//Verify function arguments
|
//Verify function arguments
|
||||||
if (!verifyProductName(product)) {
|
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) {
|
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) {
|
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) {
|
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
|
//Download .solidpkg file
|
||||||
|
|
|
@ -136,9 +136,9 @@ export default function readSsnFile(buffer: ArrayBuffer): ISsnFileEntry[] {
|
||||||
//skip 20 bytes: hash of new file
|
//skip 20 bytes: hash of new file
|
||||||
pos += 40;
|
pos += 40;
|
||||||
break;
|
break;
|
||||||
default:
|
default: //unknown field
|
||||||
//unknown field, ignore it
|
|
||||||
pos += fieldLength;
|
pos += fieldLength;
|
||||||
|
throw new Error(`Unknown entry in SSN extra field: id "${fieldId}", length "${fieldLength}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos += fileCommentLength;
|
pos += fileCommentLength;
|
||||||
|
|
Loading…
Reference in a new issue