Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.

Commit 0ba4def

Browse files
committed
SCSS error handling
1 parent ff6ce6a commit 0ba4def

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

‎scss/options.go‎ renamed to ‎scss/common.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// But hopefully, fingers crossed, this will happen.
99
package scss
1010

11+
import (
12+
"encoding/json"
13+
"fmt"
14+
)
15+
1116
type (
1217
OutputStyle int
1318
)
@@ -33,3 +38,22 @@ type Options struct {
3338
EnableEmbeddedSourceMap bool // TODO(bep) test this
3439

3540
}
41+
42+
func JSONToError(jsonstr string) (e Error) {
43+
if err := json.Unmarshal([]byte(jsonstr), &e); err != nil {
44+
e.Message = "unknown error"
45+
}
46+
return
47+
}
48+
49+
type Error struct {
50+
Status int `json:"status"`
51+
Column int `json:"column"`
52+
File string `json:"file"`
53+
Line int `json:"line"`
54+
Message string `json:"message"`
55+
}
56+
57+
func (e Error) Error() string {
58+
return fmt.Sprintf("file %q, line %d, col %d: %s ", e.File, e.Line, e.Column, e.Message)
59+
}

‎scss/libsass/transpiler.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (t *libsassTranspiler) Execute(dst io.Writer, src io.Reader) error {
6666

6767
io.WriteString(dst, result)
6868

69-
// Error handling.
70-
//libs.SassContextGetErrorStatus(goctx)
71-
//fmt.Println(strings.TrimSpace(libs.SassContextGetErrorJSON(ctx)))
69+
if status := libs.SassContextGetErrorStatus(ctx); status != 0 {
70+
return scss.JSONToError(libs.SassContextGetErrorJSON(ctx))
71+
}
7272

7373
return nil
7474
}

0 commit comments

Comments
 (0)