summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--spew/common.go8
-rw-r--r--spew/config.go16
-rw-r--r--spew/doc.go4
4 files changed, 22 insertions, 10 deletions
diff --git a/README.md b/README.md
index 2c79ebe..6d22e15 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,10 @@ options. See the ConfigState documentation for more details.
Disables invocation of error and Stringer interface methods on types
which only accept pointer receivers from non-pointer variables.
Pointer method invocation is enabled by default.
+
+* ContinueOnMethod
+ Enables recursion into types after invoking error and Stringer interface
+ methods. Recursion after method invocation is disabled by default.
```
## License
diff --git a/spew/common.go b/spew/common.go
index 11ec612..7bea858 100644
--- a/spew/common.go
+++ b/spew/common.go
@@ -151,10 +151,10 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool)
case error:
defer catchPanic(w, v)
if cs.ContinueOnMethod {
- w.Write(append(openParenBytes, []byte(iface.Error())...))
+ w.Write(openParenBytes)
+ w.Write([]byte(iface.Error()))
w.Write(closeParenBytes)
w.Write(spaceBytes)
-
return false
}
@@ -164,10 +164,10 @@ func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool)
case fmt.Stringer:
defer catchPanic(w, v)
if cs.ContinueOnMethod {
- w.Write(append(openParenBytes, []byte(iface.String())...))
+ w.Write(openParenBytes)
+ w.Write([]byte(iface.String()))
w.Write(closeParenBytes)
w.Write(spaceBytes)
-
return false
}
w.Write([]byte(iface.String()))
diff --git a/spew/config.go b/spew/config.go
index ea521cc..406171a 100644
--- a/spew/config.go
+++ b/spew/config.go
@@ -63,11 +63,14 @@ type ConfigState struct {
// inside these interface methods.
DisablePointerMethods bool
- //ContinueOnMethod specifies whether recursion should stop once
- //a Stringer or an error interface is encountered.
+ // ContinueOnMethod specifies whether or not recursion should continue once
+ // a custom error or Stringer interface is invoked. The default, false,
+ // means it will print the results of invoking the custom error or Stringer
+ // interface and return immediately instead of continuing to recurse into
+ // the internals of the data type.
//
- //It defaults to false, meaning that it does not pretty-print
- //the internals of Stringers or errors.
+ // NOTE: This flag does not have any effect if method invocation is disabled
+ // via the DisableMethods or DisablePointerMethods options.
ContinueOnMethod bool
}
@@ -255,10 +258,11 @@ func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{})
// NewDefaultConfig returns a ConfigState with the following default settings.
//
-// Indent: " "
+// Indent: " "
// MaxDepth: 0
// DisableMethods: false
-// DisablePointerMethods: false
+// DisablePointerMethods: false
+// ContinueOnMethod: false
func NewDefaultConfig() *ConfigState {
return &ConfigState{Indent: " "}
}
diff --git a/spew/doc.go b/spew/doc.go
index b899269..2e5acb2 100644
--- a/spew/doc.go
+++ b/spew/doc.go
@@ -87,6 +87,10 @@ The following configuration options are available:
which only accept pointer receivers from non-pointer variables.
Pointer method invocation is enabled by default.
+ * ContinueOnMethod
+ Enables recursion into types after invoking error and Stringer interface
+ methods. Recursion after method invocation is disabled by default.
+
Dump Usage
Simply call spew.Dump with a list of variables you want to dump: