refactor(v2): cleanup console output (#4979)

* refactor(v2): cleanup console output

* fix jest issue

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-06-16 12:37:28 +03:00 committed by GitHub
parent 8501db78a1
commit 41d9288e3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 382 additions and 339 deletions

View file

@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`getFolderContainingFile throw if no folder contain such file 1`] = `
"relativeFilePath=[index.test.ts] does not exist in any of these folders:
"File \\"index.test.ts\\" does not exist in any of these folders:
- /abcdef
- /gehij
- /klmn]"

View file

@ -441,12 +441,12 @@ describe('getElementsAround', () => {
expect(() =>
getElementsAround(['a', 'b', 'c', 'd'], -1),
).toThrowErrorMatchingInlineSnapshot(
`"Valid aroundIndex for array (of size 4) are between 0 and 3, but you provided aroundIndex=-1"`,
`"Valid \\"aroundIndex\\" for array (of size 4) are between 0 and 3, but you provided -1."`,
);
expect(() =>
getElementsAround(['a', 'b', 'c', 'd'], 4),
).toThrowErrorMatchingInlineSnapshot(
`"Valid aroundIndex for array (of size 4) are between 0 and 3, but you provided aroundIndex=4"`,
`"Valid \\"aroundIndex\\" for array (of size 4) are between 0 and 3, but you provided 4."`,
);
});
});

View file

@ -342,7 +342,7 @@ export function getElementsAround<T extends unknown>(
const max = array.length - 1;
if (aroundIndex < min || aroundIndex > max) {
throw new Error(
`Valid aroundIndex for array (of size ${array.length}) are between ${min} and ${max}, but you provided aroundIndex=${aroundIndex}`,
`Valid "aroundIndex" for array (of size ${array.length}) are between ${min} and ${max}, but you provided ${aroundIndex}.`,
);
}
const previous = aroundIndex === min ? undefined : array[aroundIndex - 1];
@ -427,7 +427,7 @@ export async function getFolderContainingFile(
// should never happen, as the source was read from the FS anyway...
if (!maybeFolderPath) {
throw new Error(
`relativeFilePath=[${relativeFilePath}] does not exist in any of these folders: \n- ${folderPaths.join(
`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join(
'\n- ',
)}]`,
);
@ -455,7 +455,7 @@ export function reportMessage(
throw new Error(message);
default:
throw new Error(
`unexpected reportingSeverity value: ${reportingSeverity}`,
`Unexpected "reportingSeverity" value: ${reportingSeverity}.`,
);
}
}

View file

@ -160,8 +160,8 @@ export function parseMarkdownString(
};
} catch (e) {
console.error(
chalk.red(`Error while parsing markdown front matter.
This can happen if you use special characters like : in frontmatter values (try using "" around that value)`),
chalk.red(`Error while parsing Markdown frontmatter.
This can happen if you use special characters in frontmatter values (try using double quotes around that value).`),
);
throw e;
}
@ -176,8 +176,7 @@ export async function parseMarkdownFile(
return parseMarkdownString(markdownString, options);
} catch (e) {
throw new Error(
`Error while parsing markdown file ${source}
${e.message}`,
`Error while parsing Markdown file ${source}: "${e.message}".`,
);
}
}