More detailed error information in wimlib_extract_pathlist()

Comments, questions, bug reports, etc.
Post Reply
joveler
Posts: 11
Joined: Wed Jan 31, 2018 2:45 pm

More detailed error information in wimlib_extract_pathlist()

Post by joveler »

Hello synchronicity, first I want to show my thanks for writing this great library!

I perfer wimlib in many aspect compared to wimgapi, and want to use it in Windows PE related program.
So I am writing ManagedWimLib, a C# wrapper library of wimlib.

I want to provide much error information as possible to user, for ease of debugging. But I am unable to get detailed information in extract feature, especially with wildcard (glob).

If I provide invalid wlidcard to wimlib_extract_paths or wimlib_extract_pathlist and wimlib is unable to find match, wimlib reports back WIMLIB_ERR_PATH_DOES_NOT_EXIST. But program cannot get information which wildcard caused this error, because wimlib directly writes that information into stderr.

Code: Select all

> E:\E\Wim>wimlib-imagex.exe extract LZX.wim 1 @ListFile.txt
[ERROR] No matches for path pattern "adsfasdf"
Note: You can use the '--nullglob' option to ignore missing files.
Note: You can use `wimlib-imagex.exe dir' to see what files and directories
      are in the WIM image.
ERROR: Exiting with error code 49:
       The path does not exist in the WIM image.E:\E\Wim>wimlib-imagex.exe extract LZX.wim 1 @ListFile.txt
String "No matches for path pattern" comes from append_matched_dentries(), which is not exposed to public.

Code: Select all

/* Append dentries matched by a path which can contain wildcard characters.  */
static int
append_matched_dentries(WIMStruct *wim, const tchar *orig_pattern,
			int extract_flags, struct append_dentry_ctx *ctx)
{
	const size_t count_before = ctx->num_dentries;
	tchar *pattern;
	int ret;

	pattern = canonicalize_wim_path(orig_pattern);
	if (!pattern)
		return WIMLIB_ERR_NOMEM;
	ret = expand_path_pattern(wim_get_current_root_dentry(wim), pattern,
				  append_dentry_cb, ctx);
	FREE(pattern);
	if (ret || ctx->num_dentries > count_before)
		return ret;
	if (extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_GLOB) {
		ERROR("No matches for path pattern \"%"TS"\"", orig_pattern);
		return WIMLIB_ERR_PATH_DOES_NOT_EXIST;
	}
	WARNING("No matches for path pattern \"%"TS"\"", orig_pattern);
	return 0;
}
Are there any other way to get this information, without piping stderr?
If not, can wimlib be patched to provide this information via progress callback?
Homes32
Posts: 1
Joined: Fri Feb 02, 2018 3:01 pm

Re: More detailed error information in wimlib_extract_pathlist()

Post by Homes32 »

I would like to second this request. It's very difficult to troubleshoot when you can't see what pattern or file is causing the error.
synchronicity
Site Admin
Posts: 474
Joined: Sun Aug 02, 2015 10:31 pm

Re: More detailed error information in wimlib_extract_pathlist()

Post by synchronicity »

Yes, a better method of error reporting is needed, but for now you can probably make do with the existing error messages. Note that the error messages don't have to go to standard error. That is the default, but it can be changed to a custom file by calling wimlib_set_error_file() or wimlib_set_error_file_by_name().
joveler
Posts: 11
Joined: Wed Jan 31, 2018 2:45 pm

Re: More detailed error information in wimlib_extract_pathlist()

Post by joveler »

Thanks for your answer, now ManagedWimLib is capable of displaying detailed message about errors!

As you suggested, I used wimlib_set_error_file_by_name() and wimlib_set_print_errors() to write wrapper method for feching last error message when wimlib functions did not return WIMLIB_ERR_SUCCESS.
Ex) Code snippet of Wim.GetLastError()

I think a function to report last error message can be added to wimlib itself, for developer's convenience.
Post Reply