Skip to content

Commit

Permalink
fix: added more debug information when a connection cannot be establi…
Browse files Browse the repository at this point in the history
…shed.
  • Loading branch information
stefa168 committed Nov 20, 2023
1 parent 099cd87 commit 1111d93
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
.port(5433)
.database("postgres");

let db_pool = PgPool::connect_with(db_opts).await?;
let db_pool = match PgPool::connect_with(db_opts).await {
Ok(pool) => pool,
Err(e) => {
return Err(
Box::try_from(format!("Failed to connect to the Database.\n{}", e)).unwrap(),
);
}
};

let json = fs::read_to_string("./inverters/Growatt v6.json").await?;
let inverter: Arc<Vec<GrowattV6EnergyFragment>> = Arc::new(serde_json::from_str(&json)?);

// https://github.com/mqudsi/tcpproxy/blob/master/src/main.rs
let listener = TcpListener::bind("0.0.0.0:5279").await?;
let listener = match TcpListener::bind("0.0.0.0:5279").await {
Ok(l) => l,
Err(e) => return Err(Box::try_from(format!("Failed to open port 5279: {}", e)).unwrap()),
};
println!("Listening on {}", listener.local_addr().unwrap());

let _listener_task: JoinHandle<io::Result<()>> = tokio::spawn(async move {
Expand Down Expand Up @@ -156,9 +166,9 @@ impl ConnectionHandler {
key,

Check warning on line 166 in src/main.rs

View workflow job for this annotation

GitHub Actions / Cargo format

Diff in /home/runner/work/growatt_server/growatt_server/src/main.rs
value
)
.execute(&self.db_pool)
.await
.unwrap();
.execute(&self.db_pool)
.await
.unwrap();
}

data
Expand All @@ -171,9 +181,9 @@ impl ConnectionHandler {
abort: CancellationToken,

Check warning on line 181 in src/main.rs

View workflow job for this annotation

GitHub Actions / Cargo format

Diff in /home/runner/work/growatt_server/growatt_server/src/main.rs
handle_data: bool,
) -> tokio::io::Result<usize>
where
R: tokio::io::AsyncRead + Unpin,
W: tokio::io::AsyncWrite + Unpin,
where
R: tokio::io::AsyncRead + Unpin,
W: tokio::io::AsyncWrite + Unpin,
{
let mut bytes_forwarded = 0;
let mut buf = [0u8; BUF_SIZE];
Expand Down

0 comments on commit 1111d93

Please sign in to comment.