Modules can report why they failed
A module had one channel back to its caller: the int returned from dpm_module_execute, handed through by dpm_execute. Any detail behind that number could only reach a log, so a caller wanting the reason had to read output rather than ask for it. dpm_set_last_error joins the exported API. A module records its reason on the context handed to its entry point, which belongs to the caller, and the caller reads it back with dpm_get_last_error. The two accessors on the context now say what they do to it: dpm_module_path becomes dpm_get_resolved_module_path, naming the value it reports rather than the setting it came from, and dpm_last_error becomes dpm_get_last_error, pairing with the setter. Path normalization moves to sanitizers.cpp, which holds the conversions that put a value written by a person into the single form the library stores it in.
This commit is contained in:
@@ -112,7 +112,7 @@ namespace {
|
||||
int list_modules(dpm_ctx* ctx) {
|
||||
dpm_cursor* cur = dpm_list_modules(ctx);
|
||||
if (!cur) {
|
||||
const char* err = dpm_last_error(ctx);
|
||||
const char* err = dpm_get_last_error(ctx);
|
||||
std::fprintf(stderr, "dpm: %s\n", err ? err : "module listing failed");
|
||||
return 1;
|
||||
}
|
||||
@@ -125,7 +125,8 @@ namespace {
|
||||
dpm_cursor_free(cur);
|
||||
|
||||
if (infos.empty()) {
|
||||
std::printf("No valid modules found in %s\n", dpm_module_path(ctx));
|
||||
std::printf("No valid modules found in %s\n",
|
||||
dpm_get_resolved_module_path(ctx));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -250,7 +251,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
dpm_module* mod = dpm_require(ctx, module_name);
|
||||
if (!mod) {
|
||||
const char* err = dpm_last_error(ctx);
|
||||
const char* err = dpm_get_last_error(ctx);
|
||||
std::fprintf(stderr, "dpm: %s\n",
|
||||
err ? err : "module could not be loaded");
|
||||
dpm_close(ctx);
|
||||
|
||||
Reference in New Issue
Block a user