Permalink
Browse files

change Error interface: now returning slice instead of a list

Conflicts:

	src/erx/StringFormatter.go
  • Loading branch information...
StepLg committed Oct 10, 2011
1 parent 03d2771 commit 48fbab271ed046fe8b47bfd67fb7359ef1227e1e
Showing with 30 additions and 22 deletions.
  1. +13 −14 src/erx/StringFormatter.go
  2. +4 −5 src/erx/XMLFormatter.go
  3. +13 −3 src/erx/erx.go
View
@@ -34,21 +34,20 @@ func formatConsole_gen(w io.Writer, err Error, tab string, level int) {
w.Write([]uint8("\n"))
}
}
-
- curErr := err.Errors().Front()
- if curErr != nil {
- w.Write([]uint8(strings.Repeat(tab, level) + "Scope errors:\n"))
- for curErr != nil {
- switch i := curErr.Value.(type) {
- case Error:
- w.Write([]uint8("------"))
- formatConsole_gen(w, i, tab, level+1)
- case os.Error:
- w.Write([]uint8(strings.Repeat(tab, level+1) + i.String()))
- default:
- w.Write([]uint8("???\n"))
+ subErrs := err.Errors()
+ if len(subErrs) > 0 {
+ w.Write([]uint8(strings.Repeat(tab, level)))
+ w.Write([]uint8("Scope errors:\n"))
+ for _, subErr := range subErrs {
+ switch i := subErr.(type) {
+ case Error :
+ formatConsole_gen(w, err, tab, level+1)
+ case os.Error :
+ w.Write([]uint8(strings.Repeat(tab, level+1)))
+ w.Write([]uint8(i.String()))
+ default :
+ w.Write([]uint8("???\n"))
}
- curErr = curErr.Next()
}
}
}
View
@@ -63,11 +63,11 @@ func formatSimpleXML_gen(w io.Writer, err Error, indent bool, level int) {
}
}
w.Write([]uint8(strings.Repeat(tab, level+1) + "</variables>" + hyphen))
- curErr := err.Errors().Front()
- if curErr != nil {
+ subErrs := err.Errors()
+ if len(subErrs) > 0 {
w.Write([]uint8(strings.Repeat(tab, level)))
- for curErr != nil {
- switch i := curErr.Value.(type) {
+ for _, subErr := range subErrs {
+ switch i := subErr.(type) {
case Error:
formatSimpleXML_gen(w, i, indent, level+1)
w.Write([]uint8(hyphen))
@@ -80,7 +80,6 @@ func formatSimpleXML_gen(w io.Writer, err Error, indent bool, level int) {
default:
w.Write([]uint8("???" + hyphen))
}
- curErr = curErr.Next()
}
}
View
@@ -18,7 +18,7 @@ func AddPathCut(path string) {
type Error interface {
Message() string
- Errors() *list.List
+ Errors() []interface{}
Variables() ErrorVariables
File() string
@@ -99,8 +99,18 @@ func (e *error_realization) Func() *runtime.Func {
return e.funcInfo
}
-func (e *error_realization) Errors() *list.List {
- return e.errors
+func (e *error_realization) Errors() []interface{} {
+ len := 0
+ for item := e.errors.Front(); item != nil; item = item.Next() {
+ len += 1
+ }
+ res := make([]interface{}, len)
+ id := 0
+ for item := e.errors.Front(); item != nil; item = item.Next() {
+ res[id] = item.Value
+ id += 1
+ }
+ return res
}
func (e *error_realization) Variables() ErrorVariables {

0 comments on commit 48fbab2

Please sign in to comment.