Skip to content

Commit 102706e

Browse files
committed
Added CompileError type
1 parent 3950ea6 commit 102706e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sass.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ static struct {
1212
{NULL}
1313
};
1414

15+
static PyObject *PySass_CompileError;
16+
1517
static PyObject *
1618
PySass_compile(PyObject *self, PyObject *args, PyObject *kwds)
1719
{
@@ -165,7 +167,7 @@ PySass_compile(PyObject *self, PyObject *args, PyObject *kwds)
165167
sass_compile(context.string);
166168

167169
if (context.string->error_status) {
168-
PyErr_SetString(PyExc_IOError, context.string->error_message);
170+
PyErr_SetString(PySass_CompileError, context.string->error_message);
169171
result = NULL;
170172
goto finalize_string;
171173
}
@@ -269,4 +271,9 @@ initsass()
269271
version = PyString_FromString("unknown");
270272
#endif
271273
PyModule_AddObject(module, "__version__", version);
274+
PySass_CompileError = PyErr_NewException("sass.CompileError",
275+
PyExc_ValueError,
276+
NULL);
277+
Py_INCREF(PySass_CompileError);
278+
PyModule_AddObject(module, "CompileError", PySass_CompileError);
272279
}

sasstests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def compile_invalid_image_path():
6363
def compile_string():
6464
actual = sass.compile(string='a { b { color: blue; } }')
6565
assert actual == 'a b {\n color: blue; }\n'
66+
with raises(sass.CompileError):
67+
sass.compile(string='a { b { color: blue; }')
68+
# sass.CompileError should be a subtype of ValueError
69+
with raises(ValueError):
70+
sass.compile(string='a { b { color: blue; }')
6671
with raises(TypeError):
6772
sass.compile(string=1234)
6873
with raises(TypeError):

0 commit comments

Comments
 (0)