-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
featureProduct featureProduct feature
Description
Background
- We want to automatically generate an error code documentation and release it as artifact in a Github Release where it can be collected by the error-catalog
- We would like to extract the error code definition of the error code builder from the source code
- The python ast package makes the parsing of the python code quite easy, see the example
code = """
class ExaError:
def __init__(self, code:str):
self._code = code
self._parameters = []
def parameter(name:str, description:str):
self._parameters.append((name,description))
return self
def test():
error=ExaError("F-BFSUP-10000")\
.parameter("param","desc")
"""
print(ast.dump(ast.parse(code), indent=4))
Output:
Module(
body=[
ClassDef(
name='ExaError',
bases=[],
keywords=[],
body=[
FunctionDef(
name='__init__',
args=arguments(
posonlyargs=[],
args=[
arg(arg='self'),
arg(
arg='code',
annotation=Name(id='str', ctx=Load()))],
kwonlyargs=[],
kw_defaults=[],
defaults=[]),
body=[
Assign(
targets=[
Attribute(
value=Name(id='self', ctx=Load()),
attr='_code',
ctx=Store())],
value=Name(id='code', ctx=Load())),
Assign(
targets=[
Attribute(
value=Name(id='self', ctx=Load()),
attr='_parameters',
ctx=Store())],
value=List(elts=[], ctx=Load()))],
decorator_list=[]),
FunctionDef(
name='parameter',
args=arguments(
posonlyargs=[],
args=[
arg(
arg='name',
annotation=Name(id='str', ctx=Load())),
arg(
arg='description',
annotation=Name(id='str', ctx=Load()))],
kwonlyargs=[],
kw_defaults=[],
defaults=[]),
body=[
Expr(
value=Call(
func=Attribute(
value=Attribute(
value=Name(id='self', ctx=Load()),
attr='_parameters',
ctx=Load()),
attr='append',
ctx=Load()),
args=[
Tuple(
elts=[
Name(id='name', ctx=Load()),
Name(id='description', ctx=Load())],
ctx=Load())],
keywords=[])),
Return(
value=Name(id='self', ctx=Load()))],
decorator_list=[])],
decorator_list=[]),
FunctionDef(
name='test',
args=arguments(
posonlyargs=[],
args=[],
kwonlyargs=[],
kw_defaults=[],
defaults=[]),
body=[
Assign(
targets=[
Name(id='error', ctx=Store())],
value=Call(
func=Attribute(
value=Call(
func=Name(id='ExaError', ctx=Load()),
args=[
Constant(value='F-BFSUP-10000')],
keywords=[]),
attr='parameter',
ctx=Load()),
args=[
Constant(value='param'),
Constant(value='desc')],
keywords=[]))],
decorator_list=[])],
type_ignores=[])
Acceptance Criteria
- We can extract the error code with message, parameters and mitigations from the python code and create the json file for the error catalog
- We can check for duplicated error codes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureProduct featureProduct feature