Skip to content

Commit e6ca9d9

Browse files
committed
Initial commit
1 parent 057ed6f commit e6ca9d9

File tree

2 files changed

+63
-25
lines changed

2 files changed

+63
-25
lines changed

src/cpython/exceptions.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class KaiError(Exception):
2+
3+
4+
def __init__(
5+
self,
6+
code: int,
7+
message: str
8+
):
9+
self.code = code
10+
self.message = message
11+
12+
super().__init__(message)

tools/errors.h.py

+51-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
import os
44

5+
errors_c = """/*
6+
This file is auto-generated. Use the tool at ../tools/errors.h.py to regenerate.
7+
*/
8+
9+
#include "errors.h"
10+
11+
const char* m3u8err_getmessage(const int code) {
12+
13+
switch (code) {
14+
%s
15+
}
16+
17+
return "Unknown error";
18+
19+
}
20+
"""
21+
22+
errors_py = """
23+
import enum
24+
25+
class KaiErrorCode(enum.Enum):
26+
%s
27+
28+
"""
29+
530
class Error:
631

732
def __init__(self, name, group, code, message):
@@ -83,6 +108,14 @@ def __lt__(self, other):
83108
error.code,
84109
error.message
85110
)
111+
112+
error.message = (
113+
error.message
114+
.strip()
115+
.replace("/*", "")
116+
.replace("*/", "")
117+
.strip()
118+
)
86119

87120
header = (
88121
prefix.strip() +
@@ -102,40 +135,33 @@ def __lt__(self, other):
102135

103136
source = os.path.join(directory, "errors.c")
104137

105-
text = """/*
106-
This file is auto-generated. Use the tool at ../tools/errors.h.py to regenerate.
107-
*/
108-
109-
#include "errors.h"
110-
111-
const char* m3u8err_getmessage(const int code) {
112-
113-
switch (code) {
114-
%s
115-
}
116-
117-
return "Unknown error";
118-
119-
}
120-
"""
121-
138+
# errors.c
122139
body = ""
123140

124141
for error in errors:
125142
body += "%scase %s:\n%sreturn \"%s\";\n" % (
126143
"\t" * 2,
127144
error.name,
128145
"\t" * 3,
129-
(
130-
error.message
131-
.strip()
132-
.replace("/*", "")
133-
.replace("*/", "")
134-
.strip()
135-
)
146+
error.message
147+
)
148+
149+
header = errors_c % body.rstrip()
150+
151+
# errors.py
152+
body = ""
153+
154+
for error in errors:
155+
if error.name.startswith("M3U8ERR_CLI_"):
156+
continue
157+
158+
body += "\t%s = %i\n" % (
159+
error.name,
160+
-error.code
136161
)
137162

138-
header = text % body.rstrip()
163+
#header = errors_py % body.rstrip()
164+
print(errors_py % body.rstrip())
139165

140166
destination = source
141167

0 commit comments

Comments
 (0)