Skip to content

Commit 99815ad

Browse files
Copilotstefankoegl
andcommitted
Improve error handling for pointer file not found
Co-authored-by: stefankoegl <[email protected]>
1 parent c4eb3b8 commit 99815ad

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

bin/jsonpointer

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ def resolve_files(args):
4848
if args.expression:
4949
ptr = args.expression
5050
elif args.pointer_file:
51-
with open(args.pointer_file) as f:
52-
content = f.read().strip()
53-
# Handle JSON-encoded strings
54-
if content.startswith('"') and content.endswith('"'):
55-
try:
56-
ptr = json.loads(content)
57-
except json.JSONDecodeError:
51+
try:
52+
with open(args.pointer_file) as f:
53+
content = f.read().strip()
54+
# Handle JSON-encoded strings
55+
if content.startswith('"') and content.endswith('"'):
56+
try:
57+
ptr = json.loads(content)
58+
except json.JSONDecodeError:
59+
ptr = content
60+
else:
5861
ptr = content
59-
else:
60-
ptr = content
62+
except FileNotFoundError:
63+
print(f"Error: Pointer file '{args.pointer_file}' not found", file=sys.stderr)
64+
sys.exit(1)
6165
else:
6266
sys.exit(1) # This should never happen because the group is required
6367

0 commit comments

Comments
 (0)