Re: [PATCHv5 7/7] Improve error handling when parsing dirstat parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Johan Herland <johan@xxxxxxxxxxx> writes:

> Not sure what you mean here. You want the caller to supply a
> string_list, to which parse_dirstat_params() appends error messages, and
> then the caller determines how to display those error messages to the
> user after parse_dirstat_params() has returned?

A rough outline of what I had in mind was:

	struct dirstat_param_error {
        	enum {
                	ERR_DIRSTAT_PERCENT = 1,
                        ERR_DIRSTAT_UNKNOWN
		} kind;
                strbuf msg;
	};

	static int parse_dirstat_params(struct diff_options *options,
		        	const char *params,
				struct dirstat_param_error *errinfo)
	{
		while (...) {
                        ...
                        else if (isdigit(*p)) {
                                ...
                                if (end - p == p_len)
                                        options->dirstat_permille = permille;
                                else {
                                        errinfo->kind = ERR_DIRSTAT_PERCENT;
                                        strbuf_add(&errinfo->msg, p, p_len);
                                        ret = -1;
                                }
                        } else {
                                errinfo->kind = ERR_DIRSTAT_UNKNOWN;
                                strbuf_add(&errinfo->sb, p, p_len);
                                ret = -1;
                        }
                        p += p_len;
                        if (*p)
                                p++;
                }
                return ret;
	}

and then the caller can extract the information to format.

But you produce more than one one error messages, so a single errinfo
approach would not work.  Instead, we should be able to pass in the
pointer to a single strbuf errmsg, and accumulate the errors in it by
calling strbuf_addf() for the same effect.  The format string given to
strbuf_addf() may probably need to be marked with _().

The caller can then check errmsg->len to see if there was an error.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]