summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThuy Linh Luu <thuy-linh.luu@edg.ag>2023-05-16 12:30:43 +0000
committerGopher Robot <gobot@golang.org>2023-05-17 16:20:09 +0000
commit6a675b9a7c73e01469b31bb1b1606b08463efeb9 (patch)
tree856b3efec40f3018d73b7dd68d7ffd18e9169b41
parent865179164ec4ce5125df3e7378b8353975224216 (diff)
downloadgo-git-6a675b9a7c73e01469b31bb1b1606b08463efeb9.tar.gz
encoding/xml: wrap charsetReader errors
This change wraps the errors from the CharsetReader function so the caller can distinguish different error conditions. Context: I have an XML file with an unknown encoding which I like to handle separately. I like to use the CharsetReader for this but the error type has not been forwarded. Change-Id: I6739a0dee04ec376cd20536be2806ce7f50c5213 GitHub-Last-Rev: ada9dd510f9a5b7f8c9473f6864077e0ed6898bd GitHub-Pull-Request: golang/go#60199 Reviewed-on: https://go-review.googlesource.com/c/go/+/494897 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/encoding/xml/xml.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go
index 1f3084e5ca..d121986944 100644
--- a/src/encoding/xml/xml.go
+++ b/src/encoding/xml/xml.go
@@ -262,6 +262,9 @@ func NewTokenDecoder(t TokenReader) *Decoder {
// or EOF before all expected end elements,
// it will return an error.
//
+// If CharsetReader is called and returns an error,
+// the error is wrapped and returned.
+//
// Token implements XML name spaces as described by
// https://www.w3.org/TR/REC-xml-names/. Each of the
// Name structures contained in the Token has the Space
@@ -634,7 +637,7 @@ func (d *Decoder) rawToken() (Token, error) {
}
newr, err := d.CharsetReader(enc, d.r.(io.Reader))
if err != nil {
- d.err = fmt.Errorf("xml: opening charset %q: %v", enc, err)
+ d.err = fmt.Errorf("xml: opening charset %q: %w", enc, err)
return nil, d.err
}
if newr == nil {