New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix default retry
option value when specifying a number
#809
Fix default retry
option value when specifying a number
#809
Conversation
Failed test case made me feel a little confused. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work for custom instances
I'll check back later, I think I'm missing something very important. |
@szmarczak hi, I studied the test carefully, Before this pr, retryCount didn't seem to be running properly. Lines 277 to 289 in f77db99
new instance created with extend should include the Maybe we should remove 413 out of the default status code? |
Hey, sorry, we just merged #797 which caused a lot of merge conflicts. Would you be able to fix the conflicts? |
source/normalize-arguments.ts
Outdated
} | ||
} else { | ||
options.retry = { | ||
..._innerDefaults.options.retry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line (91) seem to be useless.
source/normalize-arguments.ts
Outdated
|
||
if (retry !== false) { | ||
options.retry = _innerDefaults.options.retry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in #806 default configure are missing.
ce54af1
to
c568f09
Compare
@szmarczak Hi, I have made some modifications, Would you please have a look at it again? All test cases so far have only one failure, which is here, I'm not sure if there's any historical reason for it. Can you take a look Thanks! |
CI: 1 test failed
2 tests skipped
retry.ts › works when defaults.options.retry is not an object
/home/travis/build/sindresorhus/got/test/retry.ts:287
286: });
287: t.is(retryCount, 0);
288: });
Difference:
- 2
+ 0 |
Yeah, it's unclear to me why it was previously testing against |
retry
option value when specifying a number
It was introduced by 10d22b7, before the Retry-After functionality. It was testing against 0 because at that time it wasn't retrying on 413. Looks like a bug now and it should be tested against 2. |
Ah, I get it. Using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR doesn't change anything at all. The merge logic is broken, not the preNormalizeArguments
. I think it should preNormalize all sources before merging.
source/index.ts
Outdated
mutableDefaults: false | ||
}; | ||
|
||
const got = create(defaults); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave the defaults here. No need to create a new file.
source/normalize-arguments.ts
Outdated
statusCodes: new Set(), | ||
errorCodes: new Set(), | ||
maxRetryAfter: undefined | ||
...defaultOptions.options.retry as RetryOption, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. It should be defaults.retry
so we get to the same point as before.
source/merge.ts
Outdated
return iterate(options); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to move this out because if we are going to pre-normalize all options before merging, we need to avoid require
collisions (self-requiring files).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9c71db8
to
2f5da71
Compare
Renaming |
source/merge.ts
Outdated
const mergedOptions = merge({} as T & {hooks: Partial<Hooks>}, ...sources.map(source => source || {})); | ||
export function mergeOptions<T extends Options>(...sources: T[]): T & { hooks: Partial<Hooks> } { | ||
sources = sources.map(source => { | ||
if (source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would invert this an do an early return, to reduce nesting.
source/merge.ts
Outdated
export function mergeOptions<T extends Options>(...sources: T[]): T & { hooks: Partial<Hooks> } { | ||
sources = sources.map(source => { | ||
if (source) { | ||
if (!is.object(source.retry)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
source/merge.ts
Outdated
return {}; | ||
}) as T[]; | ||
|
||
const mergedOptions = merge({} as T & { hooks: Partial<Hooks> }, ...sources); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const mergedOptions = merge({} as T & { hooks: Partial<Hooks> }, ...sources); | |
const mergedOptions = merge({} as T & {hooks: Partial<Hooks>}, ...sources); |
source/merge.ts
Outdated
@@ -42,8 +42,25 @@ export default function merge<Target extends Record<string, unknown>, Source ext | |||
return target as Target & Source; | |||
} | |||
|
|||
export function mergeOptions<T extends Options>(...sources: T[]): T & {hooks: Partial<Hooks>} { | |||
const mergedOptions = merge({} as T & {hooks: Partial<Hooks>}, ...sources.map(source => source || {})); | |||
export function mergeOptions<T extends Options>(...sources: T[]): T & { hooks: Partial<Hooks> } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function mergeOptions<T extends Options>(...sources: T[]): T & { hooks: Partial<Hooks> } { | |
export function mergeOptions<T extends Options>(...sources: T[]): T & {hooks: Partial<Hooks>} { |
Co-authored-by: Szymon Marczak <sz.marczak@gmail.com>
…us#809) Co-authored-by: Szymon Marczak <sz.marczak@gmail.com>
Fixes: #806
Checklist