Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to catch schema error?
#1
Hi All,

I wanted to catch the schema error from yaml schema validation, at the same time it should not throw on console as well. I have written some sample code here, from here I could able to catch the error, but then it also throw on console when any exception happened.
import sys
import os
import oyaml as yaml
from pykwalify.core import Core, SchemaError
from pykwalify.errors import RuleError

yaml_schema = Core(source_file="config/config_full.yml", schema_files=["config/schema.yml"])

try :
    
    yaml_schema.validate(raise_exception=True)
#except (SchemaError, RuleError) as er:
except SchemaError as error:
    print('printing schema error')
    print(error)
Output:
validation.invalid --- All found errors --- ["Cannot find required key 'name'. Path: '/config/data'", "Cannot find required key 'name'. Path: '/config/data'"] printing schema error <SchemaError: error code 2: Schema validation failed: - Cannot find required key 'name'. Path: '/config/data'. - Cannot find required key 'name'. Path: '/config/data'.: Path: '/'>
I could able to catch the exception and also able to print those errors using print method, but then also it throws it on console when exception happened, which I do not want. I wanted to suppress this automatically throw it on console, since I already captured the exception/error and can print later on.

Any idea would really appreciate. Thanks.

Regards,
Maiya
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  __init__() got multiple values for argument 'schema' dawid294 4 1,898 Jan-03-2024, 09:42 AM
Last Post: buran
  try catch not working? korenron 2 812 Jan-15-2023, 01:54 PM
Last Post: korenron
  Multiprocessing queue catch get timeout Pythocodras 1 2,243 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  twisted: catch return from sql wardancer84 0 1,501 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  is this a good way to catch exceptions? korenron 14 4,594 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,101 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Missing Schema-Python Question Andwconteh 1 2,458 Jun-16-2021, 01:00 PM
Last Post: Andwconteh
  Best way to process large/complex XML/schema ? MDRI 7 6,133 May-16-2021, 09:31 PM
Last Post: snippsat
  try catch question ,get data from main code korenron 7 3,104 Nov-03-2020, 09:28 AM
Last Post: korenron
  catch input type error mcmxl22 5 2,969 Aug-11-2019, 07:33 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020