mirror of
https://github.com/golang/go.git
synced 2025-05-15 20:34:38 +00:00
better error messages, not that anyone ever sees them
R=r DELTA=30 (9 added, 1 deleted, 20 changed) OCL=28104 CL=28117
This commit is contained in:
parent
48974f553d
commit
10817ab9d2
@ -27,10 +27,9 @@ type TimeZoneError struct {
|
|||||||
os.ErrorString
|
os.ErrorString
|
||||||
}
|
}
|
||||||
|
|
||||||
func error(bytes []byte) os.Error {
|
var errShort = TimeZoneError{ "time: short zone file" }
|
||||||
// TODO(rsc): provide better diagnostics
|
var errInvalid = TimeZoneError{ "time: invalid zone file" }
|
||||||
return TimeZoneError{ "time: malformed zoneinfo"};
|
var errLong = TimeZoneError{ "time: zone file too long" }
|
||||||
}
|
|
||||||
|
|
||||||
// Simple I/O interface to binary blob of data.
|
// Simple I/O interface to binary blob of data.
|
||||||
type data struct {
|
type data struct {
|
||||||
@ -97,13 +96,13 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
|
|
||||||
// 4-byte magic "TZif"
|
// 4-byte magic "TZif"
|
||||||
if magic := d.read(4); string(magic) != "TZif" {
|
if magic := d.read(4); string(magic) != "TZif" {
|
||||||
return nil, error(bytes)
|
return nil, TimeZoneError{ "time: bad zone magic" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1-byte version, then 15 bytes of padding
|
// 1-byte version, then 15 bytes of padding
|
||||||
var p []byte;
|
var p []byte;
|
||||||
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
|
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
|
||||||
return nil, error(bytes)
|
return nil, TimeZoneError { "time: bad zone file version" }
|
||||||
}
|
}
|
||||||
vers := p[0];
|
vers := p[0];
|
||||||
|
|
||||||
@ -126,7 +125,7 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
nn, ok := d.big4();
|
nn, ok := d.big4();
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, error(bytes)
|
return nil, errShort
|
||||||
}
|
}
|
||||||
n[i] = int(nn);
|
n[i] = int(nn);
|
||||||
}
|
}
|
||||||
@ -155,7 +154,7 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
isutc := d.read(n[NUTCLocal]);
|
isutc := d.read(n[NUTCLocal]);
|
||||||
|
|
||||||
if d.error { // ran out of data
|
if d.error { // ran out of data
|
||||||
return nil, error(bytes)
|
return nil, errShort
|
||||||
}
|
}
|
||||||
|
|
||||||
// If version == 2, the entire file repeats, this time using
|
// If version == 2, the entire file repeats, this time using
|
||||||
@ -170,16 +169,16 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32;
|
var n uint32;
|
||||||
if n, ok = zonedata.big4(); !ok {
|
if n, ok = zonedata.big4(); !ok {
|
||||||
return nil, error(bytes)
|
return nil, errShort
|
||||||
}
|
}
|
||||||
z[i].utcoff = int(n);
|
z[i].utcoff = int(n);
|
||||||
var b byte;
|
var b byte;
|
||||||
if b, ok = zonedata.byte(); !ok {
|
if b, ok = zonedata.byte(); !ok {
|
||||||
return nil, error(bytes)
|
return nil, errShort
|
||||||
}
|
}
|
||||||
z[i].isdst = b != 0;
|
z[i].isdst = b != 0;
|
||||||
if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
|
if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
|
||||||
return nil, error(bytes)
|
return nil, errInvalid
|
||||||
}
|
}
|
||||||
z[i].name = byteString(abbrev[b:len(abbrev)])
|
z[i].name = byteString(abbrev[b:len(abbrev)])
|
||||||
}
|
}
|
||||||
@ -190,11 +189,11 @@ func parseinfo(bytes []byte) (zt []zonetime, err os.Error) {
|
|||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32;
|
var n uint32;
|
||||||
if n, ok = txtimes.big4(); !ok {
|
if n, ok = txtimes.big4(); !ok {
|
||||||
return nil, error(bytes)
|
return nil, errShort
|
||||||
}
|
}
|
||||||
zt[i].time = int32(n);
|
zt[i].time = int32(n);
|
||||||
if int(txzones[i]) >= len(z) {
|
if int(txzones[i]) >= len(z) {
|
||||||
return nil, error(bytes)
|
return nil, errInvalid
|
||||||
}
|
}
|
||||||
zt[i].zone = &z[txzones[i]];
|
zt[i].zone = &z[txzones[i]];
|
||||||
if i < len(isstd) {
|
if i < len(isstd) {
|
||||||
@ -216,7 +215,7 @@ func readfile(name string, max int) (p []byte, err os.Error) {
|
|||||||
n, err1 := io.FullRead(f, p);
|
n, err1 := io.FullRead(f, p);
|
||||||
f.Close();
|
f.Close();
|
||||||
if err1 == nil { // too long
|
if err1 == nil { // too long
|
||||||
return nil, TimeZoneError{ "time: zone file too long: " + name };
|
return nil, errLong;
|
||||||
}
|
}
|
||||||
if err1 != io.ErrEOF {
|
if err1 != io.ErrEOF {
|
||||||
return nil, err1;
|
return nil, err1;
|
||||||
@ -224,13 +223,22 @@ func readfile(name string, max int) (p []byte, err os.Error) {
|
|||||||
return p[0:n], nil;
|
return p[0:n], nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
func readinfofile(name string) (tx []zonetime, err os.Error) {
|
func readinfofile(name string) ([]zonetime, os.Error) {
|
||||||
buf, e := readfile(name, maxFileSize);
|
buf, err := readfile(name, maxFileSize);
|
||||||
if e != nil {
|
if err != nil {
|
||||||
return nil, e
|
goto Error;
|
||||||
}
|
}
|
||||||
tx, err = parseinfo(buf);
|
tx, err := parseinfo(buf);
|
||||||
return tx, err
|
if err != nil {
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
|
return tx, nil;
|
||||||
|
|
||||||
|
Error:
|
||||||
|
if tzerr, ok := err.(TimeZoneError); ok {
|
||||||
|
tzerr.ErrorString += ": " + name
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var zones []zonetime
|
var zones []zonetime
|
||||||
|
Loading…
x
Reference in New Issue
Block a user