uriparser / uriparser

:hocho: Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub

Home Page:https://uriparser.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error stringification?

Mango0x45 opened this issue · comments

It seems like some functions may or may not return error codes, but there doesn’t seem to be any kind of strerror()-like function for turning those error codes into an actual error message. Would you guys be open to a PR adding a uriStrError() function?

Hi @Mango0x45, I'm not sure I see value in adding a uriStrError function. If I am not mistaken, the only two user-facing errors are URI_ERROR_SYNTAX and URI_ERROR_MALLOC and all else is bad use of the uriparser API by the application code. If that is a realistic assessment, no error text other than "mal-formed URI syntax with regard to RFC 3986" and "out of memory" or so would be needed. What am I missing?

Ah, are those the only two? From what I could tell from the docs and an early issue opened here, there were a lot more that had to be handled. In that case, I don’t think there’s any need :)

@Mango0x45 there are more but I don't see much more of end-user value:

/* Shared errors */
#define URI_SUCCESS 0
#define URI_ERROR_SYNTAX 1 /* Parsed text violates expected format */
#define URI_ERROR_NULL 2 /* One of the params passed was NULL
although it mustn't be */
#define URI_ERROR_MALLOC 3 /* Requested memory could not be allocated */
#define URI_ERROR_OUTPUT_TOO_LARGE 4 /* Some output is to large for the receiving buffer */
#define URI_ERROR_NOT_IMPLEMENTED 8 /* The called function is not implemented yet */
#define URI_ERROR_RANGE_INVALID 9 /* The parameters passed contained invalid ranges */
#define URI_ERROR_MEMORY_MANAGER_INCOMPLETE 10 /* [>=0.9.0] The UriMemoryManager passed does not implement all needed functions */
/* Errors specific to ToString */
#define URI_ERROR_TOSTRING_TOO_LONG URI_ERROR_OUTPUT_TOO_LARGE /* Deprecated, test for URI_ERROR_OUTPUT_TOO_LARGE instead */
/* Errors specific to AddBaseUri */
#define URI_ERROR_ADDBASE_REL_BASE 5 /* Given base is not absolute */
/* Errors specific to RemoveBaseUri */
#define URI_ERROR_REMOVEBASE_REL_BASE 6 /* Given base is not absolute */
#define URI_ERROR_REMOVEBASE_REL_SOURCE 7 /* Given base is not absolute */
/* Error specific to uriTestMemoryManager */
#define URI_ERROR_MEMORY_MANAGER_FAULTY 11 /* [>=0.9.0] The UriMemoryManager given did not pass the test suite */

I'll close this for now until there is a clear need for a function like that.