Skip to content

Commit e0ffcc0

Browse files
authored
Merge pull request #13 from waltermaffy/config-var-fix
UnboundLocalError fix when config_file is None
2 parents 2a7ab20 + c40e297 commit e0ffcc0

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

pylnbits/config.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ def __init__(self, config_file: str = "",
2222

2323
try:
2424
if config_file:
25+
if not os.path.exists(config_file):
26+
raise FileNotFoundError(f"Config file: {config_file} not found!")
27+
2528
with open(config_file, "rb") as f:
2629
cfile = safe_load(f)
2730
print(cfile)
2831
f.close()
29-
# add file error checking
30-
self._in_key = cfile["in_key"]
31-
self._lnbits_url = cfile["lnbits_url"]
32-
self._admin_key = cfile["admin_key"]
32+
33+
# add file error checking
34+
self._in_key = cfile["in_key"]
35+
self._lnbits_url = cfile["lnbits_url"]
36+
self._admin_key = cfile["admin_key"]
37+
3338
except Exception as e:
3439
print(e)
3540
return e
@@ -63,11 +68,15 @@ def admin_headers(self):
6368

6469

6570
if __name__ == "__main__":
66-
c = Config(config_file="/Users/bitcarrot/laisee/pylnbits/config.yml")
67-
68-
print(c.in_key)
69-
print(c.admin_key)
70-
print(c.lnbits_url)
71-
print(c.headers())
72-
print(c.invoice_headers())
73-
print(c.admin_headers())
71+
c = Config(
72+
in_key="test",
73+
admin_key="test",
74+
lnbits_url="https://legend.lnbits.com"
75+
)
76+
77+
print(f"{c.in_key=}")
78+
print(f"{c.admin_key=}")
79+
print(f"{c.lnbits_url=}")
80+
print(f"{c.headers()=}")
81+
print(f"{c.invoice_headers()=}")
82+
print(f"{c.admin_headers()=}")

0 commit comments

Comments
 (0)