Skip to content

time: unbalanced quotation in Parse error message #45391

@adonovan

Description

@adonovan

See https://play.golang.org/p/z4GVpb8RQCY:

	// time (underlying problem)
	_, err := time.Parse(`"`+time.RFC3339+`"`, "0")
	fmt.Println(err) // parsing time "0" as ""2006-01-02T15:04:05Z07:00"": cannot parse "0" as """

	// encoding/json (how I encountered the error)
	err = json.Unmarshal([]byte(`0`), new(time.Time))
	fmt.Println(err) // parsing time "0" as ""2006-01-02T15:04:05Z07:00"": cannot parse "0" as """

The error message emitted by time.Parse contains unbalanced quotation marks, presumably because it uses its own trivial quote function to avoid a cycle-forming dependency on strconv. Ideally its quote function would be a little smarter. (Perhaps time.Parse could also avoid redundantly mentioning "parse" and "0" twice in the error message.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions