upkg: Improve error reporting during package load.
authorNick Bowler <nbowler@draconx.ca>
Wed, 2 Mar 2011 04:55:06 +0000 (23:55 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 3 Mar 2011 01:25:33 +0000 (20:25 -0500)
src/uobject/package.c
src/uobject/package.h
src/upkg.c

index 397d2638df34c2e59e024ef7e309c9c9891f2a23..5b29afd0a7c4f224f47e4cd9791b9c68fa5b097e 100644 (file)
@@ -157,3 +157,10 @@ GTypeModule *u_pkg_open(const char *name)
        mod->name = str_cpy_lower(pkgname, name);
        return mod;
 }
+
+bool u_pkg_is_native(GTypeModule *m)
+{
+       struct upkg_priv *priv = U_PKG_GET_PRIV(m);
+
+       return priv->native;
+}
index 32f76b848eb7323a32f68673495c73cce32b327c..47f6aa8e4ba65f5f7ba0a78d772efc3ad97cca57 100644 (file)
@@ -20,6 +20,7 @@
 #define U_OBJECT_PACKAGE_H_
 
 #include <glib-object.h>
+#include <stdbool.h>
 
 #define U_PKG_TYPE (u_pkg_get_type())
 #define U_PKG(obj) \
@@ -48,4 +49,6 @@ struct UPkgClass {
 GType u_pkg_get_type(void);
 GTypeModule *u_pkg_open(const char *name);
 
+bool u_pkg_is_native(GTypeModule *pkg);
+
 #endif
index 1e2c6626df66ec041fd941c62515b59f7b679270..19f1449a3e1aa53ab550438c43886d88909ad433 100644 (file)
@@ -336,13 +336,21 @@ int main(int argc, char **argv)
        }
 
        pkg = u_pkg_open(pkgname);
-       if (!pkg) {
-               fprintf(stderr, "failed to open package!\n");
+       if (!pkg || !g_type_module_use(pkg)) {
+               fprintf(stderr, "%s: %s: failed to open package.\n",
+                               progname, pkgname);
                return EXIT_FAILURE;
        }
 
-       if (!g_type_module_use(pkg) || !U_PKG(pkg)->pkg) {
-               fprintf(stderr, "failed to load package: %s\n", pkg->name);
+       if (!U_PKG(pkg)->pkg) {
+               if (u_pkg_is_native(pkg)) {
+                       fprintf(stderr, "%s: %s: not a UObject package.\n",
+                                       progname, pkgname);
+               } else {
+                       fprintf(stderr, "%s: %s: package not found.\n",
+                                       progname, pkgname);
+               }
+
                return EXIT_FAILURE;
        }