Skip to content

Commit d2f12e2

Browse files
committed
Made the two arguments to json_check_for_errors options, so now either or both can be used. Note that if no errors, then error_msg is now returned unallocated. Fixes #344.
1 parent 25367d5 commit d2f12e2

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/json_value_module.F90

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,24 +1909,26 @@ end subroutine wrap_json_throw_exception
19091909
!### See also
19101910
! * [[json_failed]]
19111911

1912-
subroutine json_check_for_errors(json,status_ok,error_msg)
1912+
pure subroutine json_check_for_errors(json,status_ok,error_msg)
19131913

19141914
implicit none
19151915

1916-
class(json_core),intent(inout) :: json
1917-
logical(LK),intent(out) :: status_ok !! true if there were no errors
1918-
character(kind=CK,len=:),allocatable,intent(out) :: error_msg !! the error message (if there were errors)
1916+
class(json_core),intent(in) :: json
1917+
logical(LK),intent(out),optional :: status_ok !! true if there were no errors
1918+
character(kind=CK,len=:),allocatable,intent(out),optional :: error_msg !! the error message.
1919+
!! (not allocated if
1920+
!! there were no errors)
19191921

1920-
status_ok = .not. json%exception_thrown
1922+
if (present(status_ok)) status_ok = .not. json%exception_thrown
19211923

1922-
if (.not. status_ok) then
1923-
if (allocated(json%err_message)) then
1924-
error_msg = json%err_message
1925-
else
1926-
error_msg = 'Unknown error.'
1924+
if (present(error_msg)) then
1925+
if (json%exception_thrown) then
1926+
if (allocated(json%err_message)) then
1927+
error_msg = json%err_message
1928+
else
1929+
error_msg = 'Unknown error.' ! this should never happen
1930+
end if
19271931
end if
1928-
else
1929-
error_msg = CK_''
19301932
end if
19311933

19321934
end subroutine json_check_for_errors

src/tests/jf_test_15.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ subroutine test_15(error_cnt)
5252
call json%get(p2,'logical',d)
5353
call json%get(p2,'integer',tf)
5454
call json%get(p2,'real', tf)
55+
5556
call json%check_for_errors(status_ok, error_msg) !error condition true
57+
call json%check_for_errors(status_ok) !error condition true
58+
call json%check_for_errors(error_msg) !error condition true
59+
5660
call json%initialize(print_signs=.true.) !print signs flag
5761

5862
call json%check_for_errors(status_ok, error_msg) !error condition false
63+
call json%check_for_errors(status_ok) !error condition false
64+
call json%check_for_errors(error_msg) !error condition false - not allocated
5965

6066
call file1%move(file2) !should throw an exception since points are not associated
6167
call file1%initialize()

0 commit comments

Comments
 (0)