Skip to content

Commit

Permalink
[chore] kit core/config cleanup (#7486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Channov authored Nov 4, 2022
1 parent bedc6eb commit 198f3ba
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,13 @@ const options = object(

// TODO: remove this for the 1.0 release
force: validate(undefined, (input, keypath) => {
if (typeof input !== 'undefined') {
const new_input = input ? 'warn' : 'fail';
const needs_option = new_input === 'warn';
throw new Error(
`${keypath} has been removed in favor of \`handleHttpError\`. In your case, set \`handleHttpError\` to "${new_input}"${
needs_option ? '' : ' (or leave it undefined)'
} to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
);
}
const new_input = input ? 'warn' : 'fail';
const needs_option = new_input === 'warn';
throw new Error(
`${keypath} has been removed in favor of \`handleHttpError\`. In your case, set \`handleHttpError\` to "${new_input}"${
needs_option ? '' : ' (or leave it undefined)'
} to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
);
}),

handleHttpError: validate('fail', (input, keypath) => {
Expand All @@ -282,15 +280,13 @@ const options = object(

// TODO: remove this for the 1.0 release
onError: validate(undefined, (input, keypath) => {
if (typeof input !== 'undefined') {
let message = `${keypath} has been renamed to \`handleHttpError\``;

if (input === 'continue') {
message += ', and "continue" has been renamed to "warn"';
}
let message = `${keypath} has been renamed to \`handleHttpError\``;

throw new Error(message);
if (input === 'continue') {
message += ', and "continue" has been renamed to "warn"';
}

throw new Error(message);
}),

origin: validate('http://sveltekit-prerender', (input, keypath) => {
Expand Down Expand Up @@ -432,8 +428,6 @@ function string(fallback, allow_empty = true) {
*/
function string_array(fallback) {
return validate(fallback, (input, keypath) => {
if (input === undefined) return input;

if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
throw new Error(`${keypath} must be an array of strings, if specified`);
}
Expand Down Expand Up @@ -511,10 +505,8 @@ function assert_string(input, keypath) {

/** @param {(keypath?: string) => string} fn */
function error(fn) {
return validate(undefined, (input, keypath) => {
if (input !== undefined) {
throw new Error(fn(keypath));
}
return validate(undefined, (_, keypath) => {
throw new Error(fn(keypath));
});
}

Expand Down

0 comments on commit 198f3ba

Please sign in to comment.