refactor: unify error handling behavior (#6755)

* refactor: unify error handling behavior

* revert

* normalize paths

* test...

* change

* does this work...

* fix...

* maybe fix

* maybe fix

* fix

* fix...
This commit is contained in:
Joshua Chen 2022-02-25 15:07:13 +08:00 committed by GitHub
parent dcbf9f644e
commit f903422617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 1123 additions and 299 deletions

View file

@ -48,10 +48,10 @@ export async function getDataFileData<T>(
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
const unsafeContent = Yaml.load(contentString);
return validate(unsafeContent);
} catch (e) {
} catch (err) {
// TODO replace later by error cause, see https://v8.dev/features/error-cause
logger.error`The ${params.fileType} file at path=${filePath} looks invalid.`;
throw e;
throw err;
}
}

View file

@ -178,7 +178,7 @@ export function isValidPathname(str: string): boolean {
// weird, but is there a better way?
const parsedPathname = new URL(str, 'https://domain.com').pathname;
return parsedPathname === str || parsedPathname === encodeURI(str);
} catch (e) {
} catch {
return false;
}
}

View file

@ -193,9 +193,9 @@ export function parseMarkdownString(
contentTitle,
excerpt,
};
} catch (e) {
} catch (err) {
logger.error(`Error while parsing Markdown front matter.
This can happen if you use special characters in front matter values (try using double quotes around that value).`);
throw e;
throw err;
}
}