Open Muhammad-Rabieh opened 1 year ago
⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 4 GPT-4 tickets left for the month and 1 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep edit the issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
From looking through the relevant snippets, I decided to make the following modifications:
File Path | Proposed Changes |
---|---|
exchange.go |
Modify exchange.go with contents: • Add error handling in the StartFetchAccount function to check if the period duration is zero or negative before calling the NewWorker function. If the period is not a positive duration, log an error message and return from the function. |
worker.go |
Modify worker.go with contents: • In the NewWorker function, add a condition to check if the period duration is zero or negative. If it is, log an error message and return from the function. |
rate.go |
Modify rate.go with contents: • In the GetUSDCNYFromYahoo function, add error handling for the API call. If there's an error, log it and return a default positive duration. |
I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:
Fix non-positive interval error in StartFetchAccount
sweep/fix-non-positive-interval-error
Description
This PR fixes the issue of a non-positive interval error in the StartFetchAccount function. The error occurred when fetching data from the Yahoo API, resulting in an invalid or zero interval being passed to the NewWorker function. This PR adds error handling and validation to ensure that a positive duration is always used for the interval.
Summary of Changes
- In the exchange.go file:
- Added error handling in the StartFetchAccount function to check if the period duration is zero or negative before calling the NewWorker function. If the period is not a positive duration, an error message is logged and the function returns.
- In the worker.go file:
- Modified the NewWorker function to include a condition that checks if the period duration is zero or negative. If it is, an error message is logged and the function returns.
- In the rate.go file:
- Added error handling in the GetUSDCNYFromYahoo function for the Yahoo API call. If there's an error, it is logged and a default positive duration is returned.
These changes ensure that the interval passed to the NewWorker function is always a positive duration, preventing the non-positive interval error.
File | Instructions | Progress | |
---|---|---|---|
exchange.go |
Modify exchange.go with contents: • Add error handling in the StartFetchAccount function to check if the period duration is zero or negative before calling the NewWorker function. If the period is not a positive duration, log an error message and return from the function. |
✅ Commit 66ff55f |
|
worker.go |
Modify worker.go with contents: • In the NewWorker function, add a condition to check if the period duration is zero or negative. If it is, log an error message and return from the function. |
✅ Commit 82e9f64 |
|
rate.go |
Modify rate.go with contents: • In the GetUSDCNYFromYahoo function, add error handling for the API call. If there's an error, log it and return a default positive duration. |
✅ Commit 8a0d8de |
I have finished coding the issue. I am now reviewing it for completeness. |
Here are my self-reviews of my changes at sweep/fix-non-positive-interval-error
.
Here is the 1st review
No changes required. The added error handling in the
StartFetchAccount
function inexchange.go
, theGetUSDCNYFromYahoo
function inrate.go
, and theNewWorker
function inworker.go
are logical and correctly implemented. Good job on improving the robustness of the code.
I finished incorporating these changes.
To recreate the pull request edit the issue title or description. Join Our Discord
🆒
fix : $ ./cryptoassets 2023/08/18 20:13:47 rate.go:217: GetUSDCNYFromYahoo err:code: remote-error, detail: code: remote-error, detail: error response recieved from upstream api panic: non-positive interval for NewTicker
goroutine 68 [running]: time.NewTicker(0x0?) /usr/lib/go-1.18/src/time/tick.go:24 +0x10f main.NewWorker({0xcdd160, 0xc0001f5a00}, 0x0?, 0xc272a0) /home/muhammad/sources/cryptoassets/worker.go:9 +0x57 created by main.StartFetchAccount /home/muhammad/sources/cryptoassets/exchange.go:338 +0x77 ChatGPT The error message indicates that there is an issue with creating a NewTicker in your code. The error "non-positive interval for NewTicker" suggests that the interval value passed to time.NewTicker is not a positive duration.
To locate and debug the issue, you should inspect the code in the following locations:
rate.go file: Look for the line where GetUSDCNYFromYahoo function is called. It seems there is an error response received from an upstream API. You might want to handle this error properly.
worker.go file: Examine the NewWorker function in this file. Check the arguments passed to time.NewTicker. Ensure that the interval duration you're passing is a positive value.
exchange.go file: Investigate the StartFetchAccount function in this file. Verify the arguments passed to NewWorker and ensure that the interval duration is positive.
By carefully reviewing and debugging these sections of your code, you should be able to identify and address the issue with creating the NewTicker interval. Make sure to handle error cases properly and ensure that all interval values are positive durations.
Checklist
- [X] `exchange.go` > • Add error handling in the StartFetchAccount function to check if the period duration is zero or negative before calling the NewWorker function. If the period is not a positive duration, log an error message and return from the function. - [X] `worker.go` > • In the NewWorker function, add a condition to check if the period duration is zero or negative. If it is, log an error message and return from the function. - [X] `rate.go` > • In the GetUSDCNYFromYahoo function, add error handling for the API call. If there's an error, log it and return a default positive duration.