Skip to content

Commit b159c7e

Browse files
committed
Shows error message if the file could not be opened
1 parent b43eaed commit b159c7e

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build Windows
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-windows:
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Python 3.12
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
- name: Init submodules
27+
run: |
28+
git submodule init
29+
git submodule update
30+
- name: Build script
31+
run: |
32+
./build.bat
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
name: BJSON-Editor-win-x64
36+
path: dist/

main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
from modules.pyBjson.utils import uint_to_bytes, int_to_bytes, float_to_bytes
1313

1414
def getBjsonContent(fp: str|Path):
15-
return convertBjsonToJson(fp)
15+
try:
16+
data = convertBjsonToJson(fp)
17+
except Exception as e:
18+
tkinter.messagebox.showerror("Unable to load file", f"Could not open the specified file. Error: {e}")
19+
return data
1620

1721
def addDictToTree(tree: ttk.Treeview, root: str, key: str, data: dict, count: int):
1822
if root == "":
@@ -84,6 +88,10 @@ def loadFileDataFromBjson(root, tree: ttk.Treeview, fp: str|Path):
8488
loading_label.grid(row=0, column=0)
8589
try:
8690
json_str = getBjsonContent(fp)
91+
if json_str == None:
92+
tkinter.messagebox.showerror("Unable to load file", "The file could not be loaded. The format may be incorrect or unsupported.")
93+
loading_label.grid_remove()
94+
return
8795
bjson_dict = json.loads(json_str)
8896

8997
populate_tree(tree, bjson_dict)

modules/pyBjson

0 commit comments

Comments
 (0)