hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3c3781a5fc3a3e263dece4f2ab54bbeb1fcd257c
parent 57ac568e30c2258c9b06a6b624e207dfbad6394a
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat, 30 Sep 2023 23:26:23 -0400

time::date: improve parsefail error message

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mtime/date/error.ha | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/time/date/error.ha b/time/date/error.ha @@ -1,10 +1,13 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> +use fmt; + // All possible errors returned from [[date]]. export type error = !(insufficient | invalid | parsefail); -// Converts an [[error]] into a human-friendly string. +// Converts an [[error]] into a human-friendly string. The result may be +// statically allocated. export fn strerror(err: error) const str = { match (err) { case insufficient => @@ -12,7 +15,11 @@ export fn strerror(err: error) const str = { case invalid => return "Invalid date information"; case let rn: parsefail => - // TODO: use rune 'rn' here - return "Date parsing error"; + if (rn == '\0') { + return "Date parsing error"; + }; + def FMTMSG = "Invalid date format for specifier '{}'"; + static let buf: [len(FMTMSG) + 2]u8 = [0...]; + return fmt::bsprintf(buf, FMTMSG, rn); }; };