Skip to content

Commit a67d89b

Browse files
committed
clean startup on bad args
1 parent 5fd6d99 commit a67d89b

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

.github/workflows/master.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ jobs:
6161
env:
6262
BRANCH_NAME: ${{ github.ref_name }}
6363
run: |
64-
kubectl rollout restart -n $BRANCH_NAME statefulset/master-airdrop-distributor
64+
kubectl rollout restart -n $BRANCH_NAME statefulset/master-airdrop-distributor
65+
kubectl rollout restart -n $BRANCH_NAME statefulset/airdrop-distributor-fuel-1

api/src/main.rs

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
105105
let rpc_client = RpcClient::new(args.rpc_url.clone());
106106
info!("started rpc client at {}", args.rpc_url);
107107

108-
let mut paths: Vec<_> = fs::read_dir(&args.merkle_tree_path)
109-
.unwrap()
110-
.map(|r| r.unwrap())
111-
.collect();
108+
let mut paths: Vec<_> = match fs::read_dir(&args.merkle_tree_path) {
109+
Ok(entries) => entries
110+
.filter_map(|r| r.ok())
111+
.collect(),
112+
Err(e) => {
113+
eprintln!(
114+
"Warning: Could not read merkle tree directory '{}': {}",
115+
args.merkle_tree_path.display(),
116+
e
117+
);
118+
eprintln!("Server will start in no-op mode without merkle trees");
119+
vec![]
120+
}
121+
};
112122
paths.sort_by_key(|dir| dir.path());
113123

114124
let tree = Arc::new(Mutex::new(HashMap::new()));
@@ -187,27 +197,38 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
187197
let mut vested_users: Option<HashMap<String, u128>> = None;
188198
if let Some(vested_accounts_path) = args.unvested_accounts_path {
189199
let decimals = args.unvested_accounts_decimals.unwrap_or(6);
190-
let vested_users_file = fs::File::open(vested_accounts_path)?;
191-
let vested_users_reader = std::io::BufReader::new(vested_users_file);
192-
let mut vested_users_csv = Reader::from_reader(vested_users_reader);
193-
let mut vested_users_map = HashMap::new();
194-
for record in vested_users_csv.records() {
195-
let record = match record {
196-
Ok(record) => record,
197-
Err(e) => {
198-
eprintln!("Error parsing vested user record: {}", e);
199-
continue;
200+
match fs::File::open(&vested_accounts_path) {
201+
Ok(vested_users_file) => {
202+
let vested_users_reader = std::io::BufReader::new(vested_users_file);
203+
let mut vested_users_csv = Reader::from_reader(vested_users_reader);
204+
let mut vested_users_map = HashMap::new();
205+
for record in vested_users_csv.records() {
206+
let record = match record {
207+
Ok(record) => record,
208+
Err(e) => {
209+
eprintln!("Error parsing vested user record: {}", e);
210+
continue;
211+
}
212+
};
213+
let user_pubkey = &record[0].to_string();
214+
let vested_amount =
215+
ui_amount_to_token_amount(record[1].parse::<u128>().unwrap(), decimals);
216+
vested_users_map
217+
.entry(user_pubkey.to_string())
218+
.and_modify(|e| *e += vested_amount)
219+
.or_insert(vested_amount);
200220
}
201-
};
202-
let user_pubkey = &record[0].to_string();
203-
let vested_amount =
204-
ui_amount_to_token_amount(record[1].parse::<u128>().unwrap(), decimals);
205-
vested_users_map
206-
.entry(user_pubkey.to_string())
207-
.and_modify(|e| *e += vested_amount)
208-
.or_insert(vested_amount);
221+
vested_users = Some(vested_users_map);
222+
}
223+
Err(e) => {
224+
eprintln!(
225+
"Warning: Could not open vested accounts file '{}': {}",
226+
vested_accounts_path.display(),
227+
e
228+
);
229+
eprintln!("Continuing without vested accounts data");
230+
}
209231
}
210-
vested_users = Some(vested_users_map);
211232
} else {
212233
println!("No vested accounts path provided");
213234
}

0 commit comments

Comments
 (0)